Paul Moore wrote: > 2009/9/28 Yuvgoog Greenle <ubershmekel at gmail.com>: >> 1. There is no chance of the script killing itself. In argparse and optparse >> exit() is called on every parsing error (btw because of this it sucks to >> debug parse_args in an interpreter). > > That one does worry me. I'd rather argparse (or any library function) > didn't call sys.exit on my behalf - it should raise an exception. Is > it actually true that argparse exits? (I can imagine that it might if > --help was specified, for example. An exception may not be right here, > but I still don't like the idea of a straight exit - I've used too > many C libraries that think they know when I want to exit). You can override ArgumentParser.error() to raise an exception. >> 2. There is no chance the parser will print things I don't want it to print. > > That may also be bad - for example, Windows GUI-mode programs raise an > error if they write to stdout/stderr. I could imagine using argparse > for such a program, and wanting to do something with --help other than > write to stdout and exit (a message box, for example). And yet, I'd > want access to the text argparse would otherwise write to stdout. It looks like this might not be so easy to do. I'd suggest adding a file-like object to the constructor, defaulting to sys.stderr; or maybe an ArgumentParser.print() method that can be overridden. Eric.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4