A place for my personal musings, about programming, design or whatever come across my mind

python

This irb tip is from Natasha the Robot. Often we forgot to assign an expression to a variable, you could of course use up arrow to retrieve last command and then move all the way to the front, add a variable and equal sign to it, but that is a lot of troubles. An easy […]

Going through byte of python 3, I tried to make sense of staticmethod in the section talking about class and Object variables. In the Robot class, there is a howMany class method, declared as below def howMany(): print("we have {0:d} robots".format(Robot.population)) howMany = staticmethod(howMany)def howMany(): print("we have {0:d} robots".format(Robot.population)) howMany = staticmethod(howMany) or using decorator, […]

Here is how to clear screen when you are working in the python interactive shell mode, import os os.system(’cls’)import os os.system(‘cls’) A quick google actually yields a few solutions, I find this work best for me.

As I came across the exception handling chapter, both code below should work as stated in the book (The Head First Python book, which is indented for Python 3.X, but I am running this code in Python 2.X), try: with open("man_data.txt") as man_file: print >>man_file, man with open("other_data") as other_file: print >>other_file, othertry: with open("man_data.txt") […]

Going thru the Head First Python book, which is intended for Python 3.X, although majority of the content work just as well in Python 2.X. First encountered with some variations between version 3.X and 2.X at the chapter about printing out nested lists, with tab indicating different nested level. To print a tab without a […]