New to Programming: TypeError: coercing to Unicode: need string or buffer, list found

Chris Angelico rosuav at gmail.com
Thu Apr 2 09:57:41 EDT 2015


On Fri, Apr 3, 2015 at 12:28 AM, Saran A <ahlusar.ahluwalia at gmail.com> wrote:
> Does this modification to copyFile do the job of moving the file? I haven't written a test yet.
>
> Thanks for catching the indentation for the helper functions.
>
> def copyFile(src, dest):
>> >         try:
>> >             shutil.rename(src, dest)
>> >         # eg. src and dest are the same file
>> >         except shutil.Error as e:
>> >             print('Error: %s' % e)
>> >         # eg. source or destination doesn't exist
>> >         except IOError as e:
>> >             print('Error: %s' % e.strerror)

You shouldn't need shutil here; just os.rename(src, dest) should do
the trick. But be careful! Now you have a function which moves a file,
and it's called "copyFile". If its purpose changes, so should its
name.

Have fun!

ChrisA



More information about the Python-list mailing list