assert expressions

Wanderer wanderer at dialup4less.com
Tue Jul 24 23:25:44 CEST 2012


On Jul 24, 5:22 pm, Ian Kelly <ian.g.ke... at gmail.com> wrote:
> On Tue, Jul 24, 2012 at 2:44 PM, Wanderer <wande... 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.

Thanks. Now it makes more sense.



More information about the Python-list mailing list