I've begun writing a program with an interactive prompt, and it needs to parse 
input from the user. I thought the argparse module would be
great for this, but unfortunately it insists on calling sys.exit() at any sign 
of trouble instead of letting its ArgumentError exception
propagate so that I can handle it. Overriding ArgumentParser.error doesn't 
really help since methods like parse_known_args just send a
message to be relayed to the user as an argument after swallowing ArgumentError 
(which does have useful information in its attributes). If I
wanted to figure out what actually caused the exception to be raised, I'd have 
to parse the message, which is ugly at best. I understand
that most people do want argparse to just display a message and terminate if 
the arguments supplied aren't useful, but there's a lot of
potential in the module that is crippled outside the main use case. I have to 
wonder why a module that is meant to be imported would ever
call sys.exit(), even if that is what the caller would normally do if presented 
with an exception.
-- 
CPython 3.3.2 | Windows NT 6.2.9200 / FreeBSD 9.1
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to