Pregunta

I'm using Spyder 2.2.0dev on Mac OS (10.7.6), which, as it says on startup, uses Python 2.7.3 (default, Jul 24 2012, 20:20:13). When I type

assert False

this should raise an AssertionError, as it does in my normal Python installation. However, in Spyder (both ipyton and the internal console) it does not raise any error. Does this have to be switched on somewhere? Or is this a bug?

¿Fue útil?

Solución

assertions are skipped when python is invoked with the -O options. I'm not familiar with spyder, but I would venture that some option is causing your python to be run "optimized"

Because assertions aren't always run, they are not suitible for program flow. If you want your program to stop at a certain point because a certain condition fails, raise a meaningful exception inside an if suite.

if False:
    raise ValueError("expected True, received", False)
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top