python脚本的try语句:
try配合except使用,用来检测一段代码内出现的异常并将其归类输出相关信息
vi a1.py
#!/usr/bin/python
try:
f=open('/root/ming.txt')
print(f.read())
f.close()
except IOError as reason:
print('error')
print('error reason is %s' % (reason))
:wq
python a1.py
转载于:https://blog.51cto.com/yangzhiming/2125678