我正在使用shutil.复制将一个文件的内容复制到另一个文件中。但是它导致我的原始文件被删除,错误是“文件中没有数据”
我第一次尝试这个import shutil
shutil.copy('keywords.txt', 'keywordsfinal.txt')
然后被告知文件需要以可写格式打开
^{pr2}$
但是对于这两个代码,即使我在每个.txt文件中都有一些内容,例如test1和test2,这两个文件都将返回空。在
我以前有这个工作,大约6个月后我回到我的程序,发现这个错误。感谢任何帮助。在
但是最近下面的错误也开始出现,我不知道它是什么,如果它与我的代码有任何关联。在Traceback (most recent call last):
File "C:\Python33\lib\random.py", line 249, in choice
i = self._randbelow(len(seq))
File "C:\Python33\lib\random.py", line 225, in _randbelow
r = getrandbits(k) # 0 <= r < 2**k
ValueError: number of bits must be greater than zero
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\*******\Desktop\*******\*********Python\new\Final - Copy.py", line 84, in
a = random.choice(list(f)).strip() #.strip cleans the line \n problem
File "C:\Python33\lib\random.py", line 251, in choice
raise IndexError('Cannot choose from an empty sequence')
IndexError: Cannot choose from an empty sequence