A recent coding error of mine has made me think...
I have been using assert false
instead of assert False
in one of my functions.
This function is invoked only inside try/except
clauses.
So I never noticed this "compilation error", until I actually printed the details of the exception.
Then it made me wonder if there were any runtime differences between the two.
Of course, the "false
" here can be replaced with any other undefined symbol.
Obviously, the printouts themselves would be different.
Here's a simple test that I conducted:
try:
assert false
except Exception,e:
print "false: class name = {:15}, message = {}".format(e.__class__.__name__,e.message)
try:
assert False
except Exception,e:
print "False: class name = {:15}, message = {}".format(e.__class__.__name__,e.message)
The printout of this test is:
false: class name = NameError , message = name 'false' is not defined
False: class name = AssertionError , message =
So my question is, are there any other runtime differences here? In particularly, I am interested to know if using assert(false)
over assert(False)
could somehow hinder the performance of my program.