我想shutil.copy()
将文件复制到另一个目录。我尝试执行以下代码:
copy(open("/home/dizpers/pytest/testfile1.txt", "r"), "/home/dizpers/pytest")
但是python shell向我显示了错误消息:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/shutil.py", line 116, in copy
dst = os.path.join(dst, os.path.basename(src))
File "/usr/lib/python2.7/posixpath.py", line 112, in basename
i = p.rfind('/') + 1
AttributeError: 'file' object has no attribute 'rfind'
所以,我明白为什么会出现这个问题。open()
我用函数打开文件。而且我认为我也应该打开一个这样的目录。我怎样才能做到这一点?
提前致谢!