Chriss, it works, I forgot to add the self in texture.create(self,name=name) Paul ... the first way works fine... but the second way returns this error: # TypeError: super() argument 1 must be type, not classobj #
But the important thing it that it works! Thanks everyone On Thu, Jun 18, 2009 at 4:02 PM, Paul Molodowitch <[email protected]>wrote: > > The problem is with this line: > def create(self, name='file', addPlace2dTexture=True): > >>>> self.create(name=name) <<<<< > > It's calling itself, creating an infinite recursive loop. > What you want to do is call the parent class's implementation. There > are two ways to do this: > > texture.create(self, name=name) # Explicitly invoke > parent class by name > > This will work, but means you will potentially have problems if you > ever change your inheritance hierarchy... > > super(file, self).create(name=name) # Use super to find > next class in mro (method resolution order) > > This is the more general way - it uses super to find the next class in > the mro. Unfortunately, you will potentially have problems if you use > multiple inheritance - see http://fuhm.net/super-harmful/ for full > details. > > - Paul > > On Thu, Jun 18, 2009 at 12:52 PM, sberger<[email protected]> wrote: > > > > Hi guys, I have this problem that i have no idea how to fix. > > > > I have a base class: > > class texture(shadingNode): > > def __init__(self, node=''): > > shadingNode.__init__(self, node) > > self.nodeType = 'texture' > > def create(self, name='texture'): > > return self.__init__(mc.shadingNode(self.nodeType, > asTexture=True, > > name=name)) > > > > Then I have a second class that inherit from the first one. > > Now I would like to override the create method to add an argument. > > I have no idea how to create this method override > > > > This is what I have now... > > class file(texture): > > """ my maya file node class """ > > def __init__(self, node=''): > > texture.__init__(self, node) > > self.nodeType = 'file' > > self.place2dTexture = '' > > self.setDefaultOutput('outColor') > > def create(self, name='file', addPlace2dTexture=True): > > self.create(name=name) > > if addPlace2dTexture: > > self.addPlace2dTextureNode() > > return self > > > > But when I call it like that: > > myFile = file().create() > > > > I get recursion error from python. > > > > Anyone know how to do this? > > > > > > > > > > > -- "A pit would not be complete without a Freeman coming out of it." The Vortigaunt --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/python_inside_maya -~----------~----~----~----~------~----~------~--~---
