Let's say, I write the file testFunc.py, containing
def helloWorld():
print['hello world']
When I run inside the python interpreter (v. 3.5.2)
>>> import testFunc
>>> testFunc.helloWorld()
as expected I get the error message
... error ... line 2, in helloWorld
print['hello world']
If I correct the code to
def helloWorld():
print('hello world')
and rerun only the command without closing python in the meanwhile, I get the following error message:
>>> testFunc.helloWorld()
... error ... line 2, in helloWorld
print('hello world')
So I get an error message, even though the code appearing inside the error message would be correct. Apparently Python stored the binary of the function somewhere and didn't recompile it. On the other hand, Python reads out the new source file, which doesn't contain the error anymore.
So why does Python do this? I find this behavior highly misleading. Why does Python not compare the time stamps of the source code and the temporary binary and recompile the source if it has been edited since? Is it because another instance of Python may be currently executing the temporary binary?