suppressing argparse arguments in the help

Andrea Crotti andrea.crotti.0 at
Tue Feb 28 11:14:50 EST 2012

On 02/28/2012 04:02 PM, Peter Otten wrote:
> Andrea Crotti wrote:
>> I have a script that might be used interactively but also has some
>> arguments that
>> should not be used by "normal" users.
>> So I just want to suppress them from the help.
>> I've read somewhere that the help=SUPPRESS should do what I want:
>>       parser.add_argument('-n', '--test_only',
>>                           action='store_true',
>>                           help=SUPPRESS)
>> but that's what I get from "myapp -h", which is not exactly what I was
>> looking for..
>>     -f, --first_level     ==SUPPRESS== (default: False)
>>     --never_redevelop     ==SUPPRESS== (default: False)
>> Any other solutions?
> That shouldn't happen. Did you reload() somewhere?
> argparse tests object identity not equality with SUPPRESS, so you have to
> ensure that SUPPRESS stems from the same instance of the argparse module as
> your ArgumentParser.

Ah great yes it wasn't actually the same..
but why not just use
if text != SUPPRESS
instead of:
if text is not SUPPRESS

probably the second is more safe, but they are it's still checking 
against a constant that
is very unlikely to clash with anything..

More information about the Python-list mailing list