Saturday 15 January 2011

Weird Python issue when using reload -


While using the reload in my program, I can not seem to solve a problem if my code Like MyModule import from mymodule import MYCLASS x = MYCLASS ()

Then everything works fine though if I reload the module like this Try to: import mymodule from mymodule import MYCLASS x = MYCLASS () reload (mymodule) y = MYCLASS ()

I get some strange error Not think that maybe because MYCLASS and mymodule references have changed, but really do not understand it and how to prevent it.

In such cases, what is the correct way to reload the imported modules and classes?

You should reload the following styles.

  Import mymodule x = mymodule.MYCLASS () mymodule = reload (mymodule) y = mymodule.MYCLASS ()   

If a module imports from other modules ... import ..., by reloading for other modules () it does not redefine the imported objects ??? It has to be executed in a way around the statement again, someone else is using the import and the appropriate name (module. name ) instead.

UPDATE

Recovery (x, mymodule.MYCLASS) will be incorrect , As the class is restarted, but x.__ class__ still references the old class.

  & gt; & Gt; & Gt; Isinstance (x, mymodule.myCLASS) false & gt; & Gt; & Gt; Isinstance (y, mymodule.MYCLASS) is true    

No comments:

Post a Comment