Today's Question:  What weekend projects have you created?        GIVE A SHOUT



  Use pdb to help understand python program

  As I have mentioned in Why do I need a debugger?: (3) Debugger is a good tool to help you understand code. So when I come across difficulty to understand code in bcc project, I know it is time to resort to pdb, python's debugger, to help me. The thing which confuses me is here: counts = b.get_table("counts") for k, v in sorted(counts.items(), key=lambda counts: counts[1].value): print("%-16x %-26s %8d" % (k.ip, b.ksym(k.ip), v.val...

583 0      

  Learning Python as your first programming language

Python is a widely used general-purpose, high-level programming language Its design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code than would be possible in languages such as C. Python now becomes more and more popular and is now being used the first teaching language in some universities. Why would you like to learn Python as your first programming language? Below are the reasons. Python is a high-level language with dynami...

9,428 0          ADVANTAGE PYTHON

  Python basics summary

Python is recommended by many people as the first language to be learned now. Even in some universities, it is the primary language to be taught to CS/CE students. To master this languages, we should understand some basics of it. Here we summarize some basics about this language. These basics include : string replacement with regular expression, traverse a directory, sort a list, remove duplication, dictionary ordering, dictionary, list, string conversion, date object manipulation, command line ...

9,734 0          SUMMARY PYTHON

  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...

12,266 0          PYTHON TIC-TAC-TOE

  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...


  Using Fabric to deploy web app

Many people may use FTP and rsync to synchronize codes to server, this way is fine but it may be troublesome when you need to deploy many times a day, actually there is a simple way if you can spend time on finding the fast way. We introduce Fabric today for deploying web app to remote server. Fabric is a deployment tool written with Python, the biggest feature if it is you no need to login to remote server, you can execute remote commands locally. Here is s simple deployment script written with...


  Build route graph of Hurricane Sandy

Hurricane Sandy swept US east side and landed in New York, it killed 113 persons and incurred 50 billion US dollars economic loss. Sandy is also considered as the most expensive hurricane. We will now use matplotlib and basemap libraries in Python to build a route graph of Sandy. Below is the animated GIF. Shadow is added in the graph to show the time at night, we can see from the graph that Sandy stayed a while in Panama after emerging, then it went through Cuba and became Hurricane-2. Late...


  Python object creation sequence

[The Python version described in this article is 3.x] This article aims to explore the process of creating new objects in Python. As I explained in a previous article, object creation is just a special case of calling a callable. Consider this Python code: class Joe: pass j = Joe() What happens when j = Joe() is executed? Python sees it as a call to the callable Joe, and routes it to the internal function PyObject_Call, with Joe passed as the first argument. PyObject_Call looks at the ty...