[New-bugs-announce] [issue11839] argparse: unexpected behavior of default for FileType('w')

Paolo Elvati report at bugs.python.org
Tue Apr 12 21:56:30 CEST 2011


New submission from Paolo Elvati <elvati at umich.edu>:

Hi,
when a default is specified for a file argument that is open with writing permission (FileType('w')), the default file is always created even if the argument is specified in the command line. 
For example he code:

import argparse 
parser = argparse.ArgumentParser() 
parser.add_argument( 
"-o", 
default = 'fake', 
dest = 'OutputFile', 
type = argparse.FileType('w') 
) 
args = parser.parse_args() 

will create the empty file "fake" even if the -o option is given. 
The value inside the code of args.Outputfile is not affected.

Paolo

----------
components: Library (Lib)
messages: 133598
nosy: Paolo.Elvati, bethard
priority: normal
severity: normal
status: open
title: argparse: unexpected behavior of default for FileType('w')
type: behavior
versions: Python 3.2

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11839>
_______________________________________


More information about the New-bugs-announce mailing list