sys.argv with quoted strings as option argument

Fredrik Lundh fredrik at pythonware.com
Thu Dec 11 01:23:45 EST 2003


Satya Arjunan wrote:

> I would like to send an option argument which is a quoted string with
> whitespaces to a python program. For example:
>
> $ ./myprogram.py --includedir="/usr/include /usr/local/include"
> --libdir="/usr/lib /usr/local/lib"
>
> However, sys.argv breaks the arguments whenever it encounter spaces,
> like this:
> ['./myprogram.py', '--includedir=/usr/include', '/usr/local/include',
> '--libdir=/usr/lib', '/usr/local/lib']
>
> So I can't seem to use getopt or optik to process such cases. Is there a
> good way where I can preserve such option arguments with whitespaces?

this works just fine on all platforms I have easy access to (including
windows).  what platform are you using?  does putting the *entire*
option inside the quotes ("--includedir=...") help?

</F>








More information about the Python-list mailing list