Skip to content

Instantly share code, notes, and snippets.

@quasoft
Created October 8, 2016 13:43
Show Gist options
  • Save quasoft/de02d614ea7948f108d87ef10afefcc9 to your computer and use it in GitHub Desktop.
Save quasoft/de02d614ea7948f108d87ef10afefcc9 to your computer and use it in GitHub Desktop.
Example for argument parsing with `plac` in Python
#!/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