1.文件系统常用 import os ; import shutil
os.getcwd
os.path.expanduser(~/xx)
os.path.abspath
os.path.dirname
os.path.isdir
os.path.isfile
os.path.exists
os.path.join
os.mkdir
os.listdir
os.chdir
shutil.copyfile
shutil.copytree
shutil.rmtree
os.environment
e.g. os.environ['http_proxy']
2.系统信息
sys.version_info
sys.executable
3.re
以gitconfig替换机制为例:
m = re.compile(r'^url\.(.*)\.insteadof (.*)$').match(line)
if m:
new_url = m.group(1)
old_url = m.group(2)
if url.startswith(old_url):
url = new_url + url[len(old_url):]