Error when calling superclass __init__ method
Hi, I'm getting an odd error while trying to call the __init__ method of a super class: BaseField.__init__(self) TypeError: unbound method __init__() must be called with BaseField instance as first argument (got nothing instead) This is the code: class BaseField(object): def _addFieldsToRec(self, rec, *fields): for field in fields: self.mfn[field] = rec def __init__(self): self._addFieldsToRec(1,1) self._addFieldsToRec(2, 500,501,502,503,504,505,506,507,508) class Field(BaseField): def __init__(self, value): BaseField.__init__(self) # this seems to be the offending line. self.tag = value What am I doing wrong? -- http://mail.python.org/mailman/listinfo/python-list
Re: Error when calling superclass __init__ method
Maese Fernando wrote: I'm getting an odd error while trying to call the __init__ method of a super class: BaseField.__init__(self) TypeError: unbound method __init__() must be called with BaseField instance as first argument (got nothing instead) This is the code: No, it isn't. Please provide the actual code or, better, a minimal example. Don't forget to run it to verify it shows the behaviour described above before you post it. What am I doing wrong? My bets are on BaseField.__init__() # no self Peter -- http://mail.python.org/mailman/listinfo/python-list
calling superclass __init__ when superclass is object
Hi list, I was reading this article: http://fuhm.net/super-harmful/ and didn't understand the comment about calling super(Foo, self).__init__() when Foo inherits only from object. Can someone on the list elaborate more on why one should do this? -- Evan Klitzke [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: calling superclass __init__ when superclass is object
On 8/1/07, Evan Klitzke [EMAIL PROTECTED] wrote: Hi list, I was reading this article: http://fuhm.net/super-harmful/ and didn't understand the comment about calling super(Foo, self).__init__() when Foo inherits only from object. Can someone on the list elaborate more on why one should do this? I hate to reply to my own thread, but I read this article: http://www.python.org/download/releases/2.3/mro/ and I think I understand the rationale now. If you have: class Foo(object): # stuff here class Bar(object): # stuff here class Baz(Foo, Bar): # stuff here Then if Baz calls super(Baz, self).__init__() in its __init__, and Foo makes no call super(Foo, self).__init__(), then the constructor for Bar will never be called. -- Evan Klitzke [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Calling superclass
Hello, I try to call the superclass of the ConfigParser object: class CustomizedConfParser(ConfigParser.SafeConfigParser): def get(self, section, attribute): try: return super(CustomizedConfParser, self).get(section, attribute) # [...] but that gives only return super(CustomizedConfParser, self).get(section, attribute) TypeError: super() argument 1 must be type, not classobj I don't really understand the error message. Thanks, Florian -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling superclass
Florian Lindner wrote: Hello, I try to call the superclass of the ConfigParser object: class CustomizedConfParser(ConfigParser.SafeConfigParser): def get(self, section, attribute): try: return super(CustomizedConfParser, self).get(section, attribute) # [...] but that gives only return super(CustomizedConfParser, self).get(section, attribute) TypeError: super() argument 1 must be type, not classobj I don't really understand the error message. super works only for newstyle-classes. So additionally extend CustomizedConfParser from object. diez -- http://mail.python.org/mailman/listinfo/python-list