【发布时间】:2010-12-12 08:18:59
【问题描述】:
我正在尝试将多个复制命令的成功或失败记录到日志文件中。我正在使用shutil.copy() - 例如
str_list.append(getbitmapsfrom)
game.bigbitmap = "i doubt this is there.bmp"
str_list.append(game.bigbitmap)
source = '\\'.join(str_list)
shutil.copy(source, newbigbmpname)
我强制脚本中的一个复制命令失败,并产生错误:
[Errno 2] No such file or directory: 'X:\PJ_public\PJ_Services\BSkyB-PlayJam\Content\P_NewPortal2009\1.0.0\pframes\i doubt this is is there.bmp'
这很好,但我可以捕获"Errno 2 No such file or directory" 并将其写入日志文件吗? shutil.copy() 是否返回整数值? - 我在 Python 文档中没有看到这一点。
我想我也希望能够捕获返回值,这样脚本就不会因复制失败而崩溃——我试图让它继续运行,不管错误如何。
谢谢。
【问题讨论】: