我有一个函数,试图将XML文档复制到Dropbox文件夹,但我得到:
/usr/bin/python3.5 /home/cali/PycharmProjects/Vocabulary/Vocabulary.py
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.5/tkinter/__init__.py", line 1553, in __call__
return self.func(*args)
File "/home/cali/PycharmProjects/Vocabulary/Vocabulary.py", line 232, in add_item
self.sync()
File "/home/cali/PycharmProjects/Vocabulary/Vocabulary.py", line 287, in sync
copyfile(vocabulary_path, destination_path)
File "/usr/lib/python3.5/shutil.py", line 115, in copyfile
with open(dst, 'wb') as fdst:
IsADirectoryError: [Errno 21] Is a directory: '/home/cali/Dropbox/'
Process finished with exit code 0
功能如下:
def sync(self):
path = os.path.expanduser('~/Desktop')
vocabulary_path = os.path.join(path, 'Vocabulary', 'Words.xml')
destination_path = os.path.expanduser('~/Dropbox/')
copyfile(vocabulary_path, destination_path)
我怎样才能克服这个问题?
最佳答案
可能是将文件复制到另一个文件,而不是目录。
...
destination_path = os.path.expanduser('~/Dropbox/Words.xml')
...
关于python - IsADirectoryError:[Errno 21]是目录:'/home/cali/Dropbox/',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43505121/