Re: want to show list of available options and arguments in mycommand line utility

Discussion in 'Python' started by Peter Otten, Sep 16, 2012.

  1. Peter Otten

    Peter Otten Guest

    Santosh Kumar wrote:

    > I have a script that takes an which basically takes a command line
    > argument and prints after processing. If I don't give the argument to
    > the script, it gives me a ValueError:
    >
    > ValueError: need more than 1 value to unpack
    >
    > I was trying to utilizing this space, if there is no argument I want it
    > to show:
    > usages: myscriptpy [option] [argument]
    >
    > options:
    > --help print this help message and exit
    >
    > Nothing more than that. I was looking on the argparse module, it can
    > do the stuffs I want, but
    > I don't to rewrite and mess up my current script. What should I do?


    Learning to use the argparse module is a worthwhile endeavour. You should
    rewrite and not mess up your script. This is easier if you write unit tests
    to accompany the code doing the "real work".

    Don't forget to use version control (see http://hginit.com/ for example) to
    help you back out if something goes awry.

    Also note that learning to throw away suboptimal code is important, too.
     
    Peter Otten, Sep 16, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    318
    Roland Pibinger
    Jan 11, 2007
  2. John B. Matthews
    Replies:
    0
    Views:
    783
    John B. Matthews
    Dec 9, 2011
  3. Roedy Green
    Replies:
    5
    Views:
    2,447
    Gene Wirchenko
    Dec 13, 2011
  4. Replies:
    4
    Views:
    181
    Ted Zlatanov
    Sep 13, 2006
  5. Santosh Kumar
    Replies:
    2
    Views:
    210
    Steven D'Aprano
    Sep 16, 2012
Loading...

Share This Page