Name
getopt
Synopsis
getopt(args,options,long_options=[ ])
Parses
command-line options. args is usually
sys.argv[1:]. options
is a string: each character is an option letter, followed by
':' if the option takes a parameter.
long_options is a list of strings, each a
long-option name, without the leading '--',
followed by '=' if the option takes a parameter.
When getopt encounters an error, it raises
GetoptError, an exception class supplied by the
getopt module. Otherwise,
getopt returns a pair
(
opts,args_proper
),
where opts is a list of pairs of the form
(
option,parameter
)
in the same order in which options are found in
args. Each
option is a string that starts with a
single hyphen for a short-form option or two hyphens for a long-form
one; each parameter is also a string (an
empty string for options that don’t take
parameters). args_proper is the list of
program argument strings that are left after removing the options.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access