PyDocs

Nav

Superseded modules

gnu_getopt

getopt

function (source)
  • gnu_getopt(args, shortopts, longopts=[])
getopt(args, options[, long_options]) -> opts, args

This function works like getopt(), except that GNU style scanning
mode is used by default. This means that option and non-option
arguments may be intermixed. The getopt() function stops
processing options as soon as a non-option argument is
encountered.

If the first character of the option string is '+', or if the
environment variable POSIXLY_CORRECT is set, then option
processing stops as soon as a non-option argument is encountered.
Changed in 3.14
  • 3.14: Support for returning intermixed options and non-option arguments in order.
1 Example
>>> s = 'a1 -x a2 a3 a4 --long a5 a6'
>>> args = s.split()
>>> args
['a1', '-x', 'a2', 'a3', 'a4', '--long', 'a5', 'a6']
>>> optlist, args = getopt.gnu_getopt(args, '-x:', ['long='])
>>> optlist
[(None, ['a1']), ('-x', 'a2'), (None, ['a3', 'a4']), ('--long', 'a5')]
>>> args
['a6']
from the Python docs
See Also
No see-alsos for getopt/gnu_getopt
0 Notes
No notes for gnu_getopt