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


Groups > comp.lang.python > #63532 > unrolled thread

Re: argparse action on default values

Started byTerry Reedy <tjreedy@udel.edu>
First post2014-01-08 18:20 -0500
Last post2014-01-08 18:20 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#63532 — Re: argparse action on default values

FromTerry Reedy <tjreedy@udel.edu>
Date2014-01-08 18:20 -0500
SubjectRe: argparse action on default values
Message-ID<mailman.5206.1389223231.18130.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web