1.調用系統命令需要注意:
如果是windows.python不認識path.
錯誤的:command = r'htpasswd -c c:/a.txt jane d '+un+' '+pw;
正確的:command = r'c:/apache/bin/htpasswd -c c:/a.txt jane d '+un+' '+pw;
2.去除list中的重複值
2.去除list中的重複值
tmpList=['A','B','A','B','C'];
tmpList = {}.fromkeys(tmpList).keys();
print tmpList 結果爲:
['A','B','C'];
3.性能
用Python的模塊timeit就可以知道答案了,timeit模塊可以計算完成一個表達式需要的時間:
>>> from timeit import Timer
>>> Timer('t=a; a=b; b=t', 'a=1; b=2').timeit()
0.11412903036559108
>>> Timer('a,b = b,a', 'a=1; b=2').timeit()
0.063075055628580401