[Tutor] sys.argv

Kent Johnson kent37 at tds.net
Mon Feb 13 16:10:15 CET 2006


János Juhász wrote:
> Hi,
> 
> I want to pass args to my python script on XP.
> This code
> print 'argv[0] %s' % sys.argv[0]
> print 'argv[1] %s' % sys.argv[1]
> print 'argv[2] %s' % sys.argv[2]
> 
> shows this:
> argv[0] D:\devel\home\devel\python\db\xlsxml.py
> argv[1] "K:\IT\admin\test\Flat
> argv[2] Files\2006\06.02.2006-293753-gy"
> 
> but I would see this:
> argv[0] D:\devel\home\devel\python\db\xlsxml.py
> argv[1] "K:\IT\admin\test\Flat Files\2006\06.02.2006-293753-gy"
> argv[2] ''

Since the file name includes a space you must quote it on the command 
line, otherwise the system inteprets the space as an argument separator. 
E.g.

 > python xlsxml.py "K:\IT\admin\test\Flat Files\2006\06.02.2006-293753-gy"

Kent



More information about the Tutor mailing list