遍历目录
file_or_directory = os.listdir("path")
for item in file_or_directory
for(Dirctory,subdirectory,files) in os.walk("path")
目录
os.getcwd()
os.chdir()
os.path.join(Dirctory,files)
os.makedirs("c:\\test\\test")
os.path.isfile("path")
os.path.isdir("path")
os.path.dirname()
os.path.basename()
os.rename(oldname,newname)
os.remove(fname)
os.unlink(fname)
os.removedirs()
os.system("command")
copy and remove:
import shutil
shutil.copytree("sourcedir","destdir")
shutil.rmtree("path")
字符串操作
匹配:if(str1 in str2)
str = str+str2
str = str.replace(",","")
re.sub(old_str,new_str,line): old_str 可以为re pattern
line = line.strip()
list = str.split(“,')
str = ",".join(list)
Logic: and/or/not
执行系统命令后获得返回值
修改文件
python 修改文件内容3种方法 - wc_chan - 博客园
global var
var = "Test"
Help:
package method: dir(os.path)
help(os.path.join)
print(sys.__doc__)