Problem with os.system()

Christian Heimes lists at cheimes.de
Tue Feb 24 23:55:34 EST 2009


venutaurus539 at gmail.com schrieb:
> Hello,
>          I am facing problems while using os.system() of python for
> copying a file from source to destination where the file name is in
> unicode (multi lingual characters).My python interpreter is trying to
> convert them to ascii and is failing. I tried giving unicode string as
> input for the function something like:
> 
> c = u"copy "+"\""+full_path+"\" "+dest
> os.system (c)

First of all do not use os.system() to run external programs. You'll get
in all sorts of trouble like quoting. You are far better of with the
subprocess module.

Second, why are you using an external program at all? The shutil module
contains multiple functions to copy a file or directory.

import shutil
shutil.copy(source, dest)

Christian




More information about the Python-list mailing list