Python Command Line Arguments

breamoreboy at gmail.com breamoreboy at gmail.com
Fri Apr 14 11:03:55 EDT 2017


On Friday, April 14, 2017 at 2:44:09 PM UTC+1, Bernd Nawothnig wrote:
> On 2017-04-13, Jason Friedman wrote:
> >> I have this code which I got from https://www.tutorialspoint.
> >> com/python/python_command_line_arguments.htm The example works fine but
> >> when I modify it to what I need, it only half works. The problem is the
> >> try/except. If you don't specify an input/output, they are blank at the end
> >> but it shouldn't be.
> >>
> >> import getopt
> >> import sys
> >
> > I am guessing you are wanting to parse command-line arguments rather than
> > particularly wanting to use the getopt module.
> > If I am correct you might want to spend your time instead learning the
> > argparse module:
> > https://docs.python.org/3/library/argparse.html
> > https://docs.python.org/3/howto/argparse.html
> 
> He should switch to argparse in any case because getopt is no longer
> supported and does only receive bugfixes.
> 
> Bernd
> 
> -- 
> Die Antisemiten vergeben es den Juden nicht, dass die Juden ‘Geist’
> haben – und Geld. Die Antisemiten – ein Name der
> ‘Schlechtweggekommenenen’ [Friedrich Nietzsche]

optparse is deprecated, not getopt.

Kindest regards.

Mark Lawrence.


More information about the Python-list mailing list