Why is cc's python interpreter ignoring assert statement? any other alternative to purposely throw SIGABRT error for debugging purposes?

I had a working code in python and i placed assert(False) in between an arbitrary pair of lines. Still outputs correct answer in codechef interpreter although in my own interpreter it throws AssertionError.

Hi, sorry for the very delayed reply. As you can see from Are any compiler flags set on the online judge?, the OO flag is used on Codechef, and that ignores asserts, as explained here: https://stackoverflow.com/questions/2830358/what-are-the-implications-of-running-python-with-the-optimize-flag

Here is what I have used while testing for my contest on CodeChef:

def pyassert(v):
    if v==False:
        a=2/0

And then replaced all ‘assert’ with ‘pyassert’. This gives run time error in all failing conditions.

Alternatively, You can also use,

from numpy.testing import assert_

and then replace all ‘assert’ with ‘assert_’.

2 Likes