模块内置api太多,不一一介绍,简单介绍一下那些模块,用到的时候也有方向
操作文件的模块 File
操作系统接口 os模块
对目录的操作
对文件属性的操作
os.system(‘命令’) 执行操作系统命令
异常模块
try:
x = int(input("Please enter a number: "))
break
except ValueError:
或者捕获多个
except (RuntimeError, TypeError, NameError):
print("Oops! That was no valid number. Try again ")
except ValueError:
print("Could not convert data to an integer.")
跑出异常
raise NameError('this is my namerror')
文件通配符 glob模块
命令行参数
通用工具脚本经常调用命令行参数。这些命令行参数以链表形式存储于 sys 模块的 argv 变量。
错误输出重定向和程序终止,例如:
sys.stderr.write('Warning, log file not found starting a new one\n')
Warning, log file not found starting a new one