我觉得很奇怪
with open(file, 'r')
Run Code Online (Sandbox Code Playgroud)
可以举报
FileNotFoundError: [Errno 2]
Run Code Online (Sandbox Code Playgroud)
但我无法以某种方式捕捉到并继续。我在这里遗漏了什么,还是真的希望您在 with open() 之前使用 isfile() 或类似的东西?
Reh*_*gar 14
使用try/except处理异常
try:
with open( "a.txt" ) as f :
print(f.readlines())
except Exception:
print('not found')
#continue if file not found
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
29415 次 |
| 最近记录: |