views:

192

answers:

3

How do I disable assertions in Python? That is - if it fails, I don't want it to throw an AssertionError, but to keep going.

+1  A: 

Running in optimized mode should do it.

python -OO module.py
FogleBird
+2  A: 

Use python -O:

$ python -O
>>> assert False
>>>
John Millikin
+8  A: 

Call Python with the -O flag:

test.py:

assert(False)
print 'Done'

Output:

C:\temp\py>C:\Python26\python.exe test.py
Traceback (most recent call last):
  File "test.py", line 1, in <module>
    assert(False)
AssertionError

C:\temp\py>C:\Python26\python.exe -O test.py
Done
Mark Rushakoff
not entirely obvious from the -h command. thanks!
Claudiu