Neat way to get rid of [" "] in sys.argv[n:] returns
fredrik at pythonware.com
Thu Jul 24 23:20:52 CEST 2008
> python test.py "testparameter"
> I get this output:
> 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 ''?
Since you're using slicing instead of indexing, you're printing a list,
not a single string. There is no '[ or ]' in the string itself, and no
need to replace it with anything.
To print just that string, do
print sys.argv # fetch item
print sys.argv[1:] # slice list
I suggest working through a tutorial or two. Pay special attention to
the difference between an object's value and the various ways that value
can be output.
More information about the Python-list