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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Fredrik Lundh

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

    korean_dave wrote:
    python test.py "testparame ter"
    >
    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 ''?
    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[1] # fetch item

    instead of

    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.

    </F>

Working...