This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author math_foo
Recipients Michal.Pomorski, bethard, math_foo
Date 2014-04-14.23:27:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1397518072.19.0.218288262347.issue10523@psf.upfronthosting.co.za>
In-reply-to
Content
The current behaviour takes empty lines and interprets them as empty strings. 

The attached demonstration script shows the error occurring. The first case is a simple example to illustrate what happens in the general case. The second case shows empty lines being interpreted as empty strings and assigned to arguments.

The third case, despite being very similar to the first, results in argparse exiting with an error message. Internally, what is happening is, after taking the 'foo' and 'baz' arguments and assigning them 'bar' and 'quux' respectively, it reads in an argument "", which it does not recognize. And produces the following error message:

"argparse_example.py: error: unrecognized arguments:"

The error message, in it's current form, is kind of opaque.

For the third case, if we move the blank line to between 'bar' and '-baz', the same error results, as again it tried to interpret the blank line as an argument. If we move the blank line to the start of the file, same thing again. 

If we move the blank line between '-foo' and 'bar', instead the error reads: "argparse_example.py: error: unrecognized arguments: bar" - which is at least somewhat comprehensible.

The question is, how should blank lines be handled? 

Should they be accepted as possible values for arguments? 

If they fall into spaces where arguments (versus values for arguments) are expected, should we skip them?

If the current handling is fine, I would propose updating the documentation to add the following after the paragraph that begins "Arguments read from a file ...":

"By default, blank lines are interpreted as empty strings. An empty string is not an acceptable argument; but it is an acceptable value for an argument."

And changing the way that the error from argparse is displayed so that it is more obvious what "argparse_example.py: error: unrecognized arguments:" means.
History
Date User Action Args
2014-04-14 23:27:52math_foosetrecipients: + math_foo, bethard, Michal.Pomorski
2014-04-14 23:27:52math_foosetmessageid: <1397518072.19.0.218288262347.issue10523@psf.upfronthosting.co.za>
2014-04-14 23:27:52math_foolinkissue10523 messages
2014-04-14 23:27:51math_foocreate