Created
October 8, 2016 13:43
-
-
Save quasoft/de02d614ea7948f108d87ef10afefcc9 to your computer and use it in GitHub Desktop.
Example for argument parsing with `plac` in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
def main( | |
someoption: ('Optional argument', 'option', 'o'), # Optional argument with abbreviation | |
someflag: ('Boolean flag - True if set', 'flag', 'f'), # Boolean flag | |
someint: ("Integer argument",'positional', None, float), # Explicit positional with number type | |
somestring:"String argument"='hello' # Implicit positional with default value | |
): | |
"""Example for parsing arguments with plac""" | |
print('someint value: %d' % someint) | |
print('somestring value: %s' % somestring) | |
if (someflag): | |
print("Flag -f is set") | |
else: | |
print("Flag -f is not set") | |
if (someoption): | |
print("Option -o is set: %s" % someoption) | |
else: | |
print("Option -o is not set") | |
if __name__ == '__main__': | |
import plac | |
plac.call(main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment