I created the following file.py
def function():
print('Hello')
I import and call this function:
>>> from file import function
>>> function
<function function at 0x0000022BF425FB70>
>>> function()
Hello
Now I changed function to print "Hello world" instead of "Hello" and reload file again:
>>> from file import function
>>> function
<function function at 0x0000022BF425FB70>
>>> function()
Hello
>>> import inspect
>>> inspect.getsource(function)
"def function():\n\tprint('Hello world')\n"
What confuses me is that the new function is actually reloaded (which we can see from function's source code in the last line) but it still prints "Hello". How is it possible? Also function pointer didn't change even if the source code of the function did.
Edit: I think it is not duplicate with this question. I'm not asking how to reload function. I'm asking how come that source code is changed after reloading and Python still calls old version of the function.