Is it possible to use argparse for passing optional arguments without the dash symbol?
<p>I have a program which can take in a few different arguments, and depending on what the argument is that is passed, that function is called in the python program. I know how to use sys.arv, and I have used argparse before, however I am not sure how to go about accomplishing the following with argparse..</p>

<p>Possible arguments: func1, func2, func3</p>

<p>Program could be executed with either of the following:</p>

<pre><code>python myprogram func1
python myprogram func2
python myprogram func3
</code></pre>

<p>Therefore the arg passed correlates to a function in the program. I do not want to include any dashes in the arguments so nothing like -func1 or -func2...etc. </p>

<p>Thank you!</p>

<pre><code> parser.add_argument('foo', choices=['func1','func2','func3'])
</code></pre>

<p>will accept one string, and raise an error if that string is not one of the chocies.  The results will be a namespace like</p>

<pre><code> Namespace(foo='func1')
</code></pre>

<p>and</p>

<pre><code> print(args.foo)
 # 'func1'
</code></pre>

<p>Is that what you want?</p>

<p>The subparsers mechanism does the same thing, but also lets you define added arguents that can differ depending on which subparser is given.</p>

python argparse