|
ComparisonToAlternatives
Comparison to argparse and plac
Featured The unique charm of pyopt is more apparent when you see how others currently do command line option parsing. PyoptPyopt - You write a regular function in python with a docstring and you magically expose that function to the command line. vs Argparse/optparseIn argparse you define a parser, its options, help strings, etc, and then you call the parser's main which returns a data structure. You analyze the data structure - you call whichever function you wanted to run with the relevant parameters as you arrange them. Sounds long? Compared to pyopt it is. Though it is the most flexible and powerful route. Many more things are possible with argparse, though for most use cases this isn't relevant. vs placPlac has more abilities but also a more condensed and complicated syntax. It seems less magical. For example it uses annotations for a lot of things, your function signature can easily become overwhelmed with settings. e.g... in plac: # plac example8_.py
def main(dsn, command: ("SQL query", 'option')='select * from table'):
print('executing %r on %s' % (command, dsn))
if __name__ == '__main__':
import plac; plac.call(main)in pyopt: import pyopt
expose = pyopt.Exposer()
@expose.mixed
def main(dsn, command='select * from table'):
'''command - SQL query'''
print('executing %r on %s' % (command, dsn))
if __name__ == '__main__':
expose.run()
|