Today's Question:  What does your personal desk look like?        GIVE A SHOUT

SEARCH KEYWORD -- python



  Bug caused by using changeable value as the default in "python method overload"​

In python we can set the passed in parameter's default value to make the function has the same running feature as the method overload in Java. Define a function like this: def testFunction(self, param1, param2=None, param3=None): Normally we use "None" as the parameter's default value. We can also use str/bool as the default value, but is it OK we use empty list [] as its default value? This is our test program: """ A test program using empty list as the passed-in parameter's default value. ...

   PYTHON     2019-03-11 08:52:52

  A Python assignment trap

Python has no assignment, it only has reference. Assume, we have following code snippet: >>> values = [0, 1, 2] >>> values[1] = values >>> values [0, [...], 2] Why the result is not [0, [0, 1, 2], 2], instead it goes into an infinite loop? To understand this, we need to understand some basics about Python. Python has no variables, it only has labels. When we run: values = [0, 1, 2] Python will first create a list object [0,1,2], then it labels it as values. If we later...

   Python,Assignment,Trap,Shallow copy     2013-07-19 22:08:36

  Mutli-inheritance bug between python 2.7 and 3.7

When we have run a py3.7 code under py2.x or a py2.x code under 3.x ,if a class do mutli-inheritance from 2 parent and the 2 parents also got inheritance from same parent, the different way to handle inheritance chain between python 2 and 3 will cause some running time bug: Assume we got this sample program inheritTest.py : # Purpose: Test mutli-inheritance different between python2 and 3 # Author: Yuancheng Liu # Created: 2019/05/16 class A: def getVal(self): print("cal...

   PYTHON,PYTHON 3,INHERITANCE     2019-05-16 08:33:52

  Who’s the winner: Python vs. Java, C/C++?

If there is one debate that never dies in the language community then it is this: Who’s the winner: Python Vs Java, C/C++. Obviously each has its own pros and cons, but in which language do the pros outnumber the cons or which language has better cons than others! For some it just comes down to familiarity, they like what they like!   The Numbers  But as far as the rest of the language world goes, the debate is still out there. By last count, Java, C and C++ were still winning. A...

   JAVA,INDIA,DEVELOPERS     2017-09-11 00:38:25

  The tic-tac-toe game with Python

In this tutorial, we will show how to build a tic-tac-toe game with Python. We will use functions,arrays,if statements,while statements, for loops and error handling etc. First, we need to create two functions, the first function will display the borad of the game: def print_board(): for i in range(0,3): for j in range(0,3): print map[2-i][j], if j != 2: print "|", print "" Here we used two for loops to loop through the map, this map is...

   Python,Tic-Tac-Toe     2013-07-30 02:49:09

  Where Have You Installed Your Python Packages?

Preface I am writing this article because I recently noticed in the Python community that there are several frequently asked questions: Why does running the command after installing pip result in a "executable not found" error? Why does importing a module result in a "ModuleNotFound" error? Why can I run my code in PyCharm, but it doesn't work in the command prompt? Rather than just providing solutions, it is better to teach people how to fish. To address these types of issues, you need to und...

   PYTHON,PATH,PATH_PREFIX,PACKAGE LOCATION     2023-12-17 01:03:45

  In-memory key-value store in C, Go and Python

Subtitle: Wow Go’s net library is fast On paternity leave for my second child, I found myself writing an in-memory hashmap (a poor-man’s memcached), in Go, Python and C. I was wondering how hard it would be to replace memcached, if we wanted to do something unusual with our key-value store. I also wanted to compare the languages, and, well, I get bored easily! The code is on github as Key-Value-Polyglot. Each version implements enough of the get and set commands from the mem...

   key-value,Memory,C,Python,Go     2012-03-21 09:21:51

  Unfortunate Python

Python is a wonderful language, but some parts should really have bright WARNING signs all over them. There are features that just can't be used safely and others are that are useful but people tend to use in the wrong ways. This is a rough transcript of the talk I gave at my local Python group on November 15, with some of the audience feed back mixed in. Most of this came from hanging around the Python IRC channel, something I highly recommend. [update 2011-12-19: improved "array" cr...

   Python,Defects,Deprecated methods,Warning     2011-12-20 08:27:36

  Format JSON data on Ubuntu

JSON now becomes a very popular data format because of its simplicity and light-weight. Nowadays many RESTful APIs will offer a choice of exchanging JSON data between the server and client. Sometimes the data may not be formatted and it cannot be easily read by human beings. It's frequently desired that the unformatted JSON data should be formatted before read. Today we will show a few ways to format JSON data on Ubuntu. Assume we have a json file test.json with below content. { "title": "Test"...

   RUBY,PYTHON,NODEJS,JSON,JQ,PERL,LINUX,UBUNTU,YAJL     2016-08-17 11:05:09

  Standardizing Python WSGI deployment

Over the past year I have been testing all of the new python platform as a service companies that have popped up, and I have posted my notes on my blog so that everyone can learn from my experiences. ep.io, apphosted.com, gondor.io, dotcloud.com, DjangoZoom.com, Heroku, Django hosting roundup, All and all, the platforms were very similar, they allowed you to easily host your python/django project without having to worry about managing a server or other typical system administr...

   Python,Standard,WAR,Java     2011-12-31 15:39:44