嗨,我正在处理大量文件,并尝试除语句外。
如果出于任何原因,我无权访问文件,我只想使用except语句通知用户...但是一旦通知用户,我想继续处理其他文件。 “通过”或“继续”无效。我该怎么办?
try:
process long list of files
except:
(if any error occurred with any file, just inform user on console)
and once user has been informed, resume processing of other files in the
list - this one is not working
我该怎么做?
答案 0 :(得分:0)
您的代码应类似于上面的伪代码:
for file in files:
try:
process file
except:
Inform a user and do any logging, notification you want.
Make sure that this code will not thew exception itself and pass or continue looping
如果您要重试几次以处理文件,则可能还有其他策略,例如缓存或无限while
循环。
答案 1 :(得分:0)
for file in files:
try:
process file
except:
print("Something wrong happens during processing the file '{}' ...".format(file))
(假设files
是文件名列表)。