Python常用库函数总结

1. sys

import sys
sys.argv # e.g. ['test','good']

2. os

import os

files = os.listdir('path')
os.getcwd() # 获取当前目录

os.makedirs('path') # 递归创建目录
os.mkdir('path')

path = os.path.join('','')

os.chdir('path') # 切换当前目录

3. shutil

import shutil

# Copy the file src to the file or directory dst
shutil.copy(src, dst) 

# Recursively copy an entire directory tree rooted at src.
shutil.copytree(src, dst, symlinks=False, ignore=None) 

# Recursively move a file or directory (src) to another location (dst).
shutil.move(src, dst)
Table of Contents