Where is the 'r/' coming from when I use shutil in this function? [closed]

StackOverflow https://stackoverflow.com//questions/9718919

  •  16-12-2019
  •  | 
  •  

Вопрос

def move_file(dirs,src,dst):

    src = src+".jpg"
    dst = item[1]+"/"+src

    print src
    # Moves the file        
    shutil.copyfile(src, dst)

move_file(dirs,item[0],item[1])

gives me this error:

IOError: [Errno 2] No such file or directory: 'r/001.jpg'

Even when

item = ('001','Grass')

Where is the 'r/' coming from?

Это было полезно?

Решение

Your codes a bit messed up so its not entirely clear, but it looks like you are passing item[1] (== 'Grass') to move_files as dst. You are also using item[1] inside move_files, which might be a typo, but if not then what is the value of item at that point? Or should it be dst? Either way, it looks like item == 'Grass' at the point that you're doing dst = item[1]+"/"+src, and so item[1] == 'r'.

Другие советы

I could imagine that you don't show us the real code.

If you call with move_file(dirs,item[0],item[1]), the function is defined as def move_file(dirs,src,item): and you use item[1] inside the function, Grass will turn into r.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top