Bee*_*and 12 python logging exception
我试图将许多复制命令的成功或失败记录到日志文件中.我正在使用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)
Run Code Online (Sandbox Code Playgroud)
我强制我的脚本中的一个复制命令失败,并且它生成了错误:
[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文档中看到这个描述.
我想我也希望能够捕获返回值,这样脚本就不会在复制失败时爆炸 - 我试图让它继续而不管错误.
谢谢.
jam*_*san 18
你会想看看例外部分中的Python的教程.如果shutil.copy()没有找到其中一个参数,则会引发IOError异常.您可以从异常实例中获取消息.
try:
shutil.copy(src, dest)
except IOError, e:
print "Unable to copy file. %s" % e
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18069 次 |
| 最近记录: |