Entries from 2013-04-01 to 1 month

Useful method "random.choice"

In case of choosing an element in a list randomly, I usually write a code like below.Ruby: ary = [1, 2, 3, 4, 5] print ary[rand(0...ary.length)] But in python, an useful method exists. import random ary = [1, 2, 3, 4, 5] print(random.choic…

How to use os.walk in python

This is a way that show all file names under current directory. import os for dirpath, dirnames, filenames in os.walk("."): for filename in filenames: print(os.path.join(dirpath, filename))

The Idea of "class" in python

I have studied Python recently and I found little differences between python and other programming languages.class definition: class Person(SuperClass, SuperClass2): # multiple inheritance is possible i = 1 # class variable # constructor d…