python path operations
摘要:os.madedirs:os.makedirs(path, mode=0o777, exist_ok=False)Recursive directory creation function. Like mkdir(), but makes all intermediate-level directories needed to contain the leaf directory. If the target directory with the same mode as specified already exists, raises an OSError exception if exis
阅读全文
posted @
2011-11-18 12:32
Aeol Kong
阅读(270)
推荐(0)
Python3 easyinstall error
摘要:When installing some supported packages in python3.2.2, usually got a error: (cannot remember clearly but like array object or so)Try to change the following file:%python%/Lib/distutils/command/build_scripts.py line 15:first_line_re = re.compile(b'^#!.*python[0-9.]*([ \t].*)?$')to:first_line
阅读全文
posted @
2011-11-14 14:53
Aeol Kong
阅读(189)
推荐(0)
Python: Tuples, Sets, Fractions, Types
摘要:Tuples:T = (1, 2, 3, 4)len(T)T + (5, 6)T.index(4)T.count(4)#Tuples are immutableSets:T = (1, 2, 3, 4)len(T)T + (5, 6)T.index(4)T.count(4)#Tuples are immutableFractions:from fractions import Fractionf = Fraction(2, 3)f+1f + Fraction(1, 2)Types:L = [2, 3, 4]type(L) #<class 'list'> for 3.
阅读全文
posted @
2011-10-28 17:27
Aeol Kong
阅读(202)
推荐(0)
Python Dictionary
摘要:Mapping a dictionary:D = {'food': 'Spam', 'quantity':4} #build with {}D = dict(food='Spam', quantity=4) #build with dict()D={}D['key'] = 'value' #add key,value to a dict.#Sorting Keys:for key in sorted(D): print(key, '=>', D[key])#Missing Ke
阅读全文
posted @
2011-10-28 17:17
Aeol Kong
阅读(207)
推荐(0)
Python list comprehensions
摘要:Examples from Learning Python 4th editionM = [[1,2,3],[2,3,4],[3,4,5]col2 = [row[1] for row in M][row[1] + 1 for row in M][row[1] for row in M if row[1] % 2 == 0]diag = [M[i][i] for i in [0,1,2]]G = (sum(row) for row in M) #Create a generator of row sumsnext(G) #Run the ite...
阅读全文
posted @
2011-10-26 13:05
Aeol Kong
阅读(280)
推荐(0)