assert expressions

Ian Kelly ian.g.kelly at gmail.com
Tue Jul 24 17:22:48 EDT 2012


On Tue, Jul 24, 2012 at 2:44 PM, Wanderer <wanderer at dialup4less.com> wrote:
> I'm using getopt but not at that point. I really don't have a problem.
> I'm just curious. I've never seen anything else after
> assert False,
>
> Here is some code.

It doesn't matter what you put after the assert False, because that
line is not actually reached.  When getopt sees the -q, it immediately
raises a getopt.error, which you catch and then immediately reraise as
a Usage exception, which is then caught and printed at the end.  The
chained ifs with the assert statement never even execute in this
scenario.

Seeing the assert in context, it makes more sense.  It's not
intercepting some unimplemented option and preventing the program from
proceeding; it's there as a development tool to catch programming
errors where an option is added to the getopt configuration but is not
implemented in the if chain.



More information about the Python-list mailing list