class ClassA(object):
def __init__(self, name):
print name
import moduleA; reload(moduleA)
class ClassB(moduleA.ClassA):
def __init__(self,name):
super(ClassB, self).__init__(name)
import moduleB; reload(moduleB)
class ClassC1(moduleB.ClassB):
def __init__(self,name):
super(ClassC1, self).__init__(name)
Introducir código aquí...import moduleB; reload(moduleB)
class ClassC2(moduleB.ClassB):
def __init__(self,name):
super(ClassC2, self).__init__(name)
import moduleA;
classA = moduleA.ClassA("foo")
import moduleB;
classB = moduleB.ClassB("foo")
import moduleC1; reload(moduleC1)
classC1 = moduleC1.ClassC1("foo") # workd Ok at this point
import moduleC2;
classC2 = moduleC2.ClassC2("foo")
# this time if I do this, I get the error
classC1 = moduleC1.ClassC1("foo")
# Error: TypeError: super(type, obj): obj must be an instance or subtype of type #
"Introducir código aquí..." in
moduleC2.py example)
the class
moduleB.ClassB, so when I do the second time
classC1 = moduleC1.ClassC1("foo")
there is nothing there because the adress changed. So I get that error. Is that correct?
Still, I am not sure of to design the code to keep that class "tree" mentioned before. I need the reload to update my progress to the subclasses, but by doing so,
the memory address changes.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/ee76aacf-2e05-471a-9029-56bb3f292194%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Super is a problem when a class is using multiple inheritance. But you aren't using multiple inheritance here.I would recommend to stop using reload() here. When you reload one module it will leave other interdependent modules in conflicting states. As you have identified, the memory address is changing because the reload creates another copy of all the contents in the module. This means the other modules can have old references. The C class may end up having a bad reference if the B class gets redefined. If you really need this reload functionality (which should not be left in place for a production deploy) then you could search for a "deep reload" solution online. This would at least reload everything related to what you are reloading. Or, you could remove the reloads from the modules and just manually reload in the right order as needed:reload(A)reload(B)reload(C)
On Tue, Aug 14, 2018, 7:03 AM Rudi Hammad <rudih...@gmail.com> wrote:
--By the way, I have printed out the adress of moduleB.ClassB in moduleC1.py and moduleC2.py.Because I have added reload(moduleB) in each module, that reload is changing the adress ofthe class
moduleB.ClassB, so when I do the second time
classC1 = moduleC1.ClassC1("foo")
there is nothing there because the adress changed. So I get that error. Is that correct?
Still, I am not sure of to design the code to keep that class "tree" mentioned before. I need the reload to update my progress to the subclasses, but by doing so,
the memory address changes.
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.