KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Let's say you have an object that was instantiated from a class inside a module. Now, you reload that module. The next thing you'd like to do is make that reload affect that class. mymodule.py --- class ClassChange(): def run(self): print 'one' myexperiment.py --- import mymodule from mymodule import ClassChange # why is this necessary? myObject = ClassChange() myObject.run() >>> one ### later, i changed this file, so that it says print 'two' reload(mymodule) # trick to change myObject needed here myObject.run() >>> two Do you have to make a new ClassChange object, copy myObject into that, and delete the old myObject? Or is there a simpler way? Edit: The run() method seems like a static class style method but that was only for the sake of brevity. I'd like the run() method to operate on data inside the object, so a static module function wouldn't do...
Tags (comma-separated)
Save Edits
Cancel