I'm trying to get my head around command-line arguments for Python and have been reading the Standard Library documentation about the argparse module. They mention the concept of short and long form command-line options, with short form options specified with a single dash, -
(eg -f
), and long form options specified with two dashes, --
(eg --filename
).
Nowhere does it describe the difference between the short form and long form options, except that one is obviously shorter than the other. After Googling the concepts it seems to me short form options originated long ago in C. Back then they were a single character.
My question is, should I continue to use only a single character for short form command-line options in Python? Is that what users will expect? Or is it acceptable to use two of three character abbreviations in the short options (eg -fn
)?
The maximum length of the string that you can use at the command prompt is 8191 characters.
On most UNIX platforms, command-line argument processing is handled using the getopt function. This function parses arguments passed to a program via the command line, with each option and possible argument made available to the programmer via a switch statement.
The store_true option automatically creates a default value of False. Likewise, store_false will default to True when the command-line argument is not present. The source for this behavior is succinct and clear: http://hg.python.org/cpython/file/2.7/Lib/argparse.py#l861.
I believe we could make a reference for POSIX
standard and GNU
coding guidelines. Despite there isn't a sort of 'global' standard, I suppose we should stick to these rules at least while we code for *nix.
According to the POSIX conventions each option name should be a single alphanumeric character (the alnum character classification) from the portable character set. And all options should be preceded by the '-' delimiter character.
GNU guideline adds long options
Long options consist of -- followed by a name made of alphanumeric characters and dashes. Option names are typically one to three words long, with hyphens to separate words. Users can abbreviate the option names as long as the abbreviations are unique.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With