我将文件移动到cwd的两行代码如下:
import os, shutil
shutil.move(os.path.abspath('hello_file.txt'),os.getcwd())
我确实有cwd上的一个文件,但我得到了这个回溯:
Traceback (most recent call last):
File "<ipython-input-333-f012757a9dca>", line 1, in <module>
shutil.move(os.path.abspath('hello_file.txt'),os.getcwd())
File "/Users/deepayanbhadra/anaconda3/lib/python3.6/shutil.py", line 558, in move
copy_function(src, real_dst)
File "/Users/deepayanbhadra/anaconda3/lib/python3.6/shutil.py", line 257, in copy2
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "/Users/deepayanbhadra/anaconda3/lib/python3.6/shutil.py", line 120, in copyfile
with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/deepayanbhadra/Desktop/DIY-Python-Projects/Automating Tasks/hello_file.txt'
您提供的文件路径是当前目录。你首先要换到目录上去。你可以这样做的方法之一是
这是最简单的方法,但需要大量代码才能实现
相关问题 更多 >
编程相关推荐