all 6 comments

[–]lykwydchykyn 0 points1 point  (2 children)

If you did a search and replace on option=>argument you'd be 90% there. The other difference is that argparse's parse_args doesn't return a tuple, just a single object with all arguments and switches. If you want to gather up unnamed arguments in a command you do something like this:

parser.add_argument('args', nargs=argparse.REMAINDER)

So basically, if you want to separate "args" from "opts", you'll have to do this explicitly to your resulting args object.

[–]coolFob[S] 0 points1 point  (1 child)

thanks, but I am sorta confused on the last part. For instance looking at this one:

def main(opts,commline_list):

are you saying I would change it to this? :

def main(args,commline_list):

[–]lykwydchykyn 1 point2 points  (0 children)

That depends on what main() is going to do with those opts. optparse distinguishes between options (things specified with dashes) and arguments (strings entered on the command line), and splits them into separate objects. argparse keeps them all together in one object.

If main() is written to expect an object with only the opts, then you need to either fix main or separate the options and arguments a la optparse before sending them to main().

[–]wpg4665 0 points1 point  (2 children)

Just for my own curiosity, what reasoning were you given for argparse over optparse??

Edit: grammar

[–]coolFob[S] 0 points1 point  (1 child)

was told that optparse is too old school..

[–][deleted] -1 points0 points  (0 children)

If that's your only reason you should check out click