好吧,我还有一个问题。我实现了错误检查,但由于某种原因它仍然不起作用。我仍然得到一个python错误,而不是我刚才在程序中写的错误。

Traceback (most recent call last):
  File "E:/python/copyfile.py", line 31, in <module>
    copyFile()
  File "E:/python/copyfile.py", line 8, in copyFile
    file1 = open(source,"r")
IOError: [Errno 2] No such file or directory: 'C:/Users/Public/asdf.txt'

最佳答案

查看标准库中的shutil模块:

shutil.copyfile(src, dst)

http://docs.python.org/2/library/shutil.html#shutil.copyfile

10-07 15:42