Entries from 2013-04-21 to 1 day

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