Skip to content
Advertisement

running python script with argparser

Trying to run my script using argparser, where the program does not run, unless correct argument is in place, however it does not seem to work;

JavaScript
JavaScript

Also when the –sync arg is given it ask for another, then when I add one more argument. SYNC, then it returns attribute error.

Edit

Trying to make the program run the develop.Autogit.run

Working..

Had to also add args as argument in the run funciton i am calling.

Advertisement

Answer

I think what you are trying to accomplish is setting a default, typically this is done with ArgumentParser.set_defaults(). You need to do this with the uninitialised function. See this example:

JavaScript

As an aside, you will have more problems with your snippet as you are defining the same parameter (--sync) in multiple places. When using subparsers it is customary to make these positional (no leading --) so they act as subcommands.


Here is a typical command line that I would use with subcommands:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement