发布时间:2019-08-09 08:50:58编辑:auto阅读(1595)
try:
可能产生运行时错误的代码
except:
错误恢复代码
Man: Is this your car?
Other man: No.
Woman: What color is it?
Bye.
Go on
#!/usr/local/python
with open('E:/python code/other/tmp/test.txt') as fd:
for each_line in fd:
if each_line.find(':') > 0:
(role, line_spoken) = each_line.split(':',1)
print(role),
print(' said '),
print(line_spoken),
#!/usr/local/python
import os,sys
try:
with open('E:/python code/other/tmp/test.txt') as fd:
for each_line in fd:
try:
(role, line_spoken) = each_line.split(':', 1)
print(role),
print(' said '),
print(line_spoken),
except ValueError:
pass
except IOError:
print('The file is missing.')
上一篇: python如何学习
下一篇: CCSP笔记3
47496
45799
36797
34327
28970
25600
24445
19613
19113
17635
5469°
6051°
5573°
5640°
6575°
5378°
5380°
5887°
5858°
7174°