Neat way to get rid of [" "] in sys.argv[n:] returns

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Thu Jul 24 23:10:15 CEST 2008


korean_dave a écrit :
> so, i code this:
> -----------------------------
> #!/usr/bin/python
> 
> import sys
> import os
> 
> for param in os.environ.keys():
>     print "%20s %s" % (param,os.environ[param])
> 
> print(os.environ['PATH'])
> 
> print(sys.argv[1:])
> --------------------------
> and then when i type in -->
> 
> python test.py "testparameter"
> 
> I get this output:
> 
> -------------
> ['testparameter']
> ----------------
> 
> Is there a way to neatly, in one call to the parameter, to get rid of
> the [' and '] without bothering to replace() '[ with "" and replace()
> '] with ''?

exact-but-useless-answer:

   print sys.argv[1]


to-the-point-answer:

   print " ".join(sys.argv[1:])


and-if-I-may-ask:
- do you understand why you get these "[' ']" ?





More information about the Python-list mailing list