argparse - optional python arguments without dashes but with additional parameters? -
What I would like to do in Python accept the following format arguments:
  PY START | STOP | Position | MOVEABS & lt; X & gt; & Lt; Y & gt; | Morell & lt; X & gt; & Lt; Y & gt; In other words,   -  I do not want to deal with hyphens;  
 -  I have many possibilities, one of them  
 -  each one is mutually exclusive;  
 -  Some commands (Easy Transfer and Pathology) have additional required logic, but these arguments should not exist with any other logic.   
 Can it be done in dragon and will I use arguments or something else? Thank you.   
 
   arguments will move with subpursors  <[START Former>  import argparse parser = argparse.ArgumentParser (prog = 'script.py') sp = parser.add_subparsers (dest = 'cmd') for CMD in ',' STOP ',' STATUS ']: [' MOVEABS ',' MOVEREL ']: SPP = sp.add_parser (CMD) SPP.add_argument (' x ', type = float) spp.add_argument (' y ', sp.add_parser (cmd) for CMD in type = float) Parser.print_help () args = parser.parse_args () print (args)    Product of choice:  
  2137: ~ / mypy $ python2 7 stack23304740.py MOVEREL -h Usage: script.py [-h] {start, stop, position, MOVEABS, MOVEREL} ... positional logic: {start, s Top, position, MOVEABS, MOVEREL} Optional argument: -H, --help Show this help message and exit usage: script.py MOVEREL [-h] xy static argument: xy optional argument: -H, --help This help Show the message and exit    and  
  2146: ~ / mypy $ python2.7 Stack 23304740.py MOVEREL 1.0 2.0 ... Namespace (CMD = 'Moverail', x = 1.0, y = 2.0)    and  
  2147: ~ / mypy $ python2.7 stack23304740.py startup ... Namespace (CMD = 'start')    MOVEREL arguments   and  & lt; Y & gt; Click , but then you would  args ['<'> instead of  args.y  Y & gt; '] .  metavar = '& lt; X & gt;  can be used to change the display but not namespace names.   You can edit the  spp.add_argument ('point', Nargs = 2, type = float) . Unfortunately this is a bug that prevents us from using Metawara in this  nargs = 2  case.   
 
 
 
Comments
Post a Comment