1、程序重启
import os
import sys
python = sys.executable
os.execl(python, python, *sys.argv)
2、字典推导式
d = {key: value for (key, value) in iterable}
3、遍历文件夹下所有文件
import os
def listdir(path, list_name): #传入存储的list
for file in os.listdir(path):
file_path = os.path.join(path, file)
if os.path.isdir(file_path):
listdir(file_path, list_name)
else:
list_name.append(file)
item_path = unicode(r'E:\文件夹', 'utf-8')
result = []
listdir(item_path, result)
windows下如果path包含中文路径,可以这样使用 listdir(unicode(path,"utf-8"), list_name)
python文件夹操作:python文件文件夹操作_Yuuu_le的博客-CSDN博客_python 文件夹
4、2.7使用3.0+的print
from __future__ import print_function
print(text1, text2, sep = ",",end = ",")