James B <skilletau...@gmail.com> added the comment:

I have encountered this issue(python 2.7) with respect to positional arguments 
that begin with a dash (linux/ bash).

In the following example, the parser requires three positional arguments. I 
attempted to encase the arguments in single-quotes as that is expected in 
general to result in strings to be correctly handled (these args are API keys, 
so they could contain shell-unfriendly chars like - and &).

./tool.py  arg1 'arg2' '-arg3&otherstuff' 

You'll note there are no optional arguments in this example, it just boils down 
to a positional argument being broken up on parse.

Needless to say it was quite confusing to see the script complain after passing 
in what would typically be perfectly valid strings in most other apps / scripts.

Is it possible to get argparse to correctly notice and handle shell-appropriate 
single-quoting methods(dont break down a string that has been implied as a 
complete token via ' ')

As it stands, it appears I have two workaround options: 1) adopt the ./tool.py 
-- <postional args> convention mentioned in this thread, or 2) escape leading 
dashes in positional argument strings to avoid this issue.

----------
nosy: +skilletaudio

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue9334>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to