Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #63532

Re: argparse action on default values

From Terry Reedy <tjreedy@udel.edu>
Subject Re: argparse action on default values
Date 2014-01-08 18:20 -0500
References <7353849.WXZ0zEZ0QV@horus>
Newsgroups comp.lang.python
Message-ID <mailman.5206.1389223231.18130.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: argparse action on default values Terry Reedy <tjreedy@udel.edu> - 2014-01-08 18:20 -0500

csiph-web