sys.argv with quoted strings as option argument

D

Diez B. Roggisch

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?

Under Linux, this works. So most probably this is a problem of your shell
(under windows?) Anther solution might be to specify every argument with
its own key like this:

../myprogram --include-dir=foo --include-dir=bar

Using getopt, you can build up the list on your own.

Diez
 
S

Satya Arjunan

Hi everyone,

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?

satya
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top