sys.arg whitespace problem

Diez B. Roggisch deets at nospam.web.de
Sun Nov 18 16:40:42 CET 2007


bryan rasmussen schrieb:
> Hi,
> 
> Basically I want to get sys.argv[1: ] but the problem is that actually
> the argument should maintain whitespace. Thus if the arguments are
> something something with only one space between them, or something
> something with three spaces between them I should be able to maintain
> the exact whitespace between arguments.


That has nothing to do with python - it's a question of your shell. 
Because the shell is responsible for parsing the arguments, possibly 
instantiating variables or even executing subcalls. The resulting 
argument list is then passed to the C-main of python.

So to pass arguments containing whitespace to python, do

python myscript.py "an argument with whitespac in it" "another one"

Diez



More information about the Python-list mailing list