In the examples I saw that all handle only a fixed command line argument, and the voluntary number of alternative command line arguments. So I wonder if it can handle more than one positional argument? If yes, then how does this and how commandline logic are specified? Thank you.
So I wonder if it can handle more than one positional argument? If so, how does this and how the command line logic has been specified?
Okay, for example, a long time ago in controlling several non-option arguments, maybe it's a good place to start.
Here is a trivial example; Place the following code in argtest.py
:
import argparse def parse_args (): p = argparse.ArgumentParser () p.add_argument ('- option1', '-1') p.add_argument ('- option2', '-2') p.add_argument ('commandline1') p.add_argument ('commandline2') returns p.parse_args () if __name__ == '__main__': p = Parse_args () Print
and then:
Python argtest.py Usage: argtest.py [-h] [- Option 1 OPTION1] [ - Option 2 OPTION2] Commandline 1 Commandline 2 argtest.py: Error: Very Low Logic
Or:
Python argtest.py Hello world namespace (commandline1 = 'Hello', command line2 = 'world', and Aeon 1 = no option 2 = no)
No comments:
Post a Comment