Python shutil.copy2上的IOError

Python shutil.copy2上的IOError,python,Python,运行下面的代码之后 import os, shutil, glob, sys source_dir = sys.argv[1] list = ['file1', 'fil2'] for seek in list: if seek == 'file1': dest_dir = '/root/my_dir' elif seek == 'file2': dest_dir = '/root/my_dir'

运行下面的代码之后

import os, shutil, glob, sys
source_dir = sys.argv[1]

list = ['file1', 'fil2']
for seek in list:
        if seek == 'file1':
                dest_dir = '/root/my_dir'
        elif seek == 'file2':
                dest_dir = '/root/my_dir'
        paths = [(z, os.path.join(dest_dir, os.path.split(z)[1]))
                for z in glob.glob(os.path.join(source_dir, seek))]
        for p in paths:
                if os.path.isfile(p[1]):
                        new_path = p[1] + '.bak'
                        print ('File "{0}" already exists; 
                                moving to "{1}"'.format(p[1], new_path))
                        shutil.move(p[1], new_path)
                shutil.copy2(p[0], p[1])
生成以下异常:

File "./config1.py", line 22, in <module>
  shutil.copy2(p[0], p[1])
File "/usr/local/lib/python3.0/shutil.py", line 99, in copy2
  copyfile(src, dst)
File "/usr/local/lib/python3.0/shutil.py", line 54, in copyfile
  copyfileobj(fsrc, fdst)
File "/usr/local/lib/python3.0/shutil.py", line 30, in copyfileobj
  fdst.write(buf)
File "/usr/local/lib/python3.0/io.py", line 1055, in write
  self._flush_unlocked()
File "/usr/local/lib/python3.0/io.py", line 1082, in _flush_unlocked
    n = self.raw.write(self._write_buf)
IOError: [Errno 28] No space left on device
文件“/config1.py”,第22行,在
shutil.copy2(p[0],p[1])
文件“/usr/local/lib/python3.0/shutil.py”,第99行,copy2
复制文件(src、dst)
copyfile中的文件“/usr/local/lib/python3.0/shutil.py”,第54行
copyfileobj(fsrc、fdst)
copyfileobj中的文件“/usr/local/lib/python3.0/shutil.py”,第30行
fdst写入(buf)
写入文件“/usr/local/lib/python3.0/io.py”,第1055行
self._flush_unlocked()
文件“/usr/local/lib/python3.0/io.py”,第1082行,在
n=self.raw.write(self.\u write\u buf)
IOError:[Errno 28]设备上没有剩余空间
您的驱动器已满吗

还有,那些台词

    if seek == 'file1':
            dest_dir = '/root/my_dir'
    elif seek == 'file2':
            dest_dir = '/root/my_dir'
都是无用的,在这两种情况下,您都将dest_dir设置为相同的值

照办

dest_dir = '/root/my_dir'
list = ['file1', 'fil2']
for seek in list:
    # your stuff
或者,如果你计划有其他不同的案例

for seek in list:
    if seek in ('file1', 'fil2'):
        dest_dir = '/root/my_dir'
    elif seek in ('other_case', 'another_case'):
        dest_dir = '/foo'

愚蠢的问题,但是你的磁盘空间用完了吗?
设备上没有剩余空间了吗?@Andreas,是的。。没有空间,我知道,但在执行此代码后,我没有发现磁盘为什么会被此代码填满..?@Jaiswal您正在复制(多个)文件,这会占用额外的磁盘空间-目标驱动器上似乎没有足够的可用空间。复制的文件有多大?目标驱动器上还有多少磁盘空间?可能也没有索引节点了。。。
df-k/root/my_dir
df-i/root/my_dir
的输出是什么?您到底在使用哪个文件系统?