Access to raw command line?

Pieter Edelman p.edelman at
Thu Apr 26 09:04:30 CEST 2007


I'm currently writing a command-line program in Python, which takes
commands in the form of:
So pretty standard stuff. In my case, ARGS is a list of image files.

One of the possible options is to specify a file holding information
about the photos. You'd specify it with (in this particular case) the -
t switch, and you can specify multiple files by repeating this switch:
./ -t info1.gpx -t info2.gpx -t info3.gpx *jpg

Now, one of the users has quite a lot of info files, and asked me if
it's possible to use a wildcard in specifying these, so he would just
have to do:
./ -t *.gpx *.jpg

This seems like a sensible option at first sight, but it's difficult
to implement because the wildcard is expanded by the shell, so
sys.argv gets a list containing "-t", all .gpx files and all .jpg
files. With this list, there's no way to tell which files belong to
the "-t" switch and which are arguments (other than using the

One possible way to work around this is to get the raw command line
and do the shell expansions ourselves from within Python. Ignoring the
question of whether it is worth the trouble, does anybody know if it
is possible to obtain the raw (unexpanded) command line?
Alternatively,  does anybody have suggestion of how to do this in a
clean way?


More information about the Python-list mailing list