argparse action on default values

Terry Reedy tjreedy at udel.edu
Wed Jan 8 18:20:15 EST 2014


On 1/8/2014 1:20 PM, Florian Lindner wrote:

> I use argparse from Python 3.3.3 with a custom action that normalizes
> path arguments:

> This works fine when there is actually a --config=path supplied. But
> it's not being applied on default arguments.

This behavior is how I interpret the doc.
http://docs.python.org/3/library/argparse.html#the-add-argument-method

"action - The basic type of action to be taken when this argument is 
encountered at the command line."

"default - The value produced if the argument is absent from the command 
line."

> Of course, I could use "default = norm_path('~/.foobar/config')"

Do that.

> but I expect that custom actions are applied to default values as well.

See doc quote.

> The store action works alike for default and supplied values.

It would make no sense to ignore defaults. There may be some 
undocumented subtleties in the interaction of defaults and actions.

-- 
Terry Jan Reedy




More information about the Python-list mailing list