sys.argv with quoted strings as option argument
Satya Arjunan
satya at ttck.keio.ac.jp
Thu Dec 11 19:52:35 EST 2003
It is not python's error. It is because another sh script which I
envoked to call the python script removed the quotes, like this:
satya at kona printargs $ ls -al
total 16
drwxr-xr-x 2 satya users 4096 Dec 12 00:51 .
drwxr-xr-x 3 satya users 4096 Dec 12 00:48 ..
-rwxr-xr-x 1 satya users 53 Dec 12 09:46 printargs.py
-rwxr-xr-x 1 satya users 58 Dec 12 09:47 sh-python
satya at kona printargs $ cat printargs.py
#!/usr/bin/env ./sh-python
import sys
print sys.argv
satya at kona printargs $ cat sh-python
#!/bin/sh
echo /usr/bin/python $*
exec /usr/bin/python $*
satya at kona printargs $ ./printargs.py --libdir="/usr/lib /usr/local/lib"
/usr/bin/python ./printargs.py --libdir=/usr/lib /usr/local/lib
['./printargs.py', '--libdir=/usr/lib', '/usr/local/lib']
Thanks for your responses. It helped me to find out the problem.
satya
Fredrik Lundh wrote:
>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>
>
>
>
>
>
>
--
Satya Nanda Vel Arjunan
Institute for Advanced Biosciences
Keio University
http://satya.host.sk/
More information about the Python-list
mailing list