在一篇很牛的介紹python中list去重的部落格(http://www.peterbe.com/plog/uniqifiers-benchmark)中收集到的: view plaincopy to clipboardprint? 1. from random import shuffle, randint 2. import re 3. from sets import Set 4. def f1(seq): # Raymond Hettinger 5. #
用py簡單的實現了一個統計程式碼的小工具#/usr/bin/pythonimport os#count the line of a single filedef CountLine(path): tempfile = open(path) res = 0 for lines in tempfile: res += 1 print "%s %d" %(path, res) #output the file
在編譯jpype python setup.py build 時遇到如下錯誤:4-2.4/src/native/python/jpype_javaarray.oIn file included from src/native/python/jpype_javaarray.cpp:18:src/native/python/include/jpype_python.h:24:20: error: Python.h: No such file or
坑爹啊,記憶力不行,老是記不住,都用了這麼久了,記在這裡以後來翻。DirectiveMeaningNotes%aLocale’s abbreviated weekdayname. %ALocale’s full weekday name. %bLocale’s abbreviated monthname. %BLocale’s full month name. %cLocale’s appropriate date andtime representation. %dDay of the
最近,想在我的YouMoney(http://code.google.com/p/youmoney/)裡面增加提取使用者作業系統版本資訊。比如windows使用者,可能要返回Windows XP ,或者Windows 2003, 蘋果使用者應該返回Mac OS X 10.5.8。用了很多辦法,包括在mac系統裡調用系統命令,取環境變數,等等。最後無意發現,原來python裡裡面有個platform模組就可以幹這件事情。省事啊! mac上這麼幹 localhost:~ apple$
最近研究研究了css,少不了去網上分析一下別人的網頁, 但很多網站的css檔案都是要麼寫在一行,要麼一個換行都沒有,看起來極其痛苦,所以寫一個指令碼轉換一下,轉換為比較有可讀性的格式。下面就是這個指令碼:import string, sysimport re, StringIOTAB=4def format(ss): f = open (ss, "r") data = f.read() f.close() dlen = len(data) i = 0