标准库介绍
操作系统接口
>>> import os
>>> os.getcwd() # Return the current working directory
'C:\\Python37'
>>> os.chdir('/server/accesslogs') # Change current working directory
>>> os.system('mkdir today') # Run the command mkdir in the system shell
>>> import shutil
>>> shutil.copyfile('data.db', 'archive.db')
'archive.db'
>>> shutil.move('/build/executables', 'installdir')
'installdir'
---------------------
文件通配符
>>> import glob
>>> glob.glob('*.py')
['primes.py', 'random.py', 'quote.py']
命令行参数
通用实用程序脚本通常需要处理命令行参数。这些参数作为列表存储在sys模块的argv属性中。
>>> import sys
>>> print(sys.argv)
['demo.py', 'one', '