471,353 Members | 1,536 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,353 software developers and data experts.

sys.argv with quoted strings as option argument

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

--
Satya Nanda Vel Arjunan
Institute for Advanced Biosciences
Keio University
http://satya.host.sk/

Jul 18 '05 #1
1 2064
> 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
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by jab3 | last post: by
5 posts views Thread by mwebel | last post: by
56 posts views Thread by subramanian100in | last post: by
11 posts views Thread by vicky | last post: by
2 posts views Thread by Ben Bacarisse | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.