want to show list of available options and arguments in my command line utility

Peter Otten __peter__ at web.de
Sun Sep 16 03:23:46 EDT 2012


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.




More information about the Python-list mailing list