optparse question

Pat Pat at junk.net
Tue Jan 27 02:02:59 CET 2009


Up until today, I never needed to pass any arguments to a Python program.

I did all the requisite reading and found that I should use optparse 
instead of getopt.   I read the documentation and since the words 
"simple" and "easy" often appeared in the examples and documentation, I 
just knew that it would be a snap to implement.

Problem is that all I wanted to do was pass a one flag to the program 
"-d", for to enable debug mode.  Several hours later I gave up after 
optparse complained about every variation I tried.

What does it take to pass single parameter to a program? 
http://docs.python.org/library/optparse.html stated that programs always 
have options.  Is that so?  What about "dir /s"?

getopt resolved my immediate need, but I would like to know how one 
could use optparse to extract out the options from something like "dir 
/s /b".




More information about the Python-list mailing list