個人筆記祸憋,不定期更新
2018-1-6
- 使用Pyinstaller打包Python程序(自定義圖標(biāo))
pyinstaller -F -c --icon="iconPATH" programPATH
- psutil常用方法
psutil.cpu_count() # CPU邏輯數(shù)量 psutil.cpu_count(logical=False) # CPU物理核心 psutil.cpu_percent(0)# CPU使用率 psutil.virtual_memory()#物理內(nèi)存信息 psutil.pids() # 所有進(jìn)程ID
p = psutil.Process(pid) # 獲取指定進(jìn)程 p.name() # 進(jìn)程名稱 p.exe() # 進(jìn)程exe路徑 p.cmdline() # 進(jìn)程啟動的命令行 p.cpu_times() # 進(jìn)程使用的CPU時間 p.memory_info() #進(jìn)程使用的內(nèi)存 p.terminate() # 結(jié)束進(jìn)程
2018-1-7
-
列表去重
>>> test = ['a','a','b','c','c'] >>> test = list(set(test)) >>> prinrt(test) ['a','b','c']
-
items()
以列表形式返回可遍歷的(鍵, 值) 元組數(shù)組testDict = {'谷歌':'Google','百度':'Baidu','聯(lián)想':'Lenovo'} print(testDict.items()) for key,values in testDict.items(): print(key,values)
運(yùn)行結(jié)果
dict_items([('谷歌', 'Google'), ('百度', 'Baidu'), ('聯(lián)想', 'Lenovo')]) 谷歌 Google 百度 Baidu 聯(lián)想 Lenovo
-
tuple = sorted(form.items(), key=lambda e: e[0], reverse=False)
- sorted中的各個參數(shù)
- form.items()為迭代的對象
- key用于接收一個函數(shù),實現(xiàn)自定義排序
- reverse=False 為升序排序翰舌,反之則為降序
- lambda為匿名函數(shù)恋博,e用于接收form.items()的元素作為參數(shù)
- e[0]取出key值,為按鍵排序
- e[1]取出value值,為按值排序
綜上,這行代碼的意思是兄猩,將字典form按鍵升序排列,返回一個元組tuple
- sorted中的各個參數(shù)
2018-1-30
- 文本替換
with open('1.txt','r',encoding='utf-8') as f,open('2.txt','w',encoding='utf-8') as f2:
for i in f:
i = i.replace('old','new')
f2.write(i)
2018-2-12
- 使用pyintaller打包應(yīng)用出現(xiàn)報錯
UnicodeDecodeError: 'gbk' codec can't decode byte 0xb3 in position 172: illegal multibyte sequence
解決方案:將Python中文文件名修改為英文