I have following code
import imp
from my_module import MyClass
import my_module
imp.reload(my_module)
print(MyClass == my_module.MyClass) # Result is False
Why the MyClass imported from my_module is not equal to my_module.MyClass?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The answer to your question is hidden at the line, where you reload your module. After such reload, python recompiles the whole module, recreate all objects inside it and load it.
So, when reloading module, there is created completely new class
MyClassthat is not the same object as it was before.You can check this code: