Using super()
Pupeno
pupeno at pupeno.com
Wed Jul 19 09:06:52 EDT 2006
Laszlo Nagy wrote:
> Pupeno írta:
>> Hello,
>> I have a class called MyConfig, it is based on Python's
>> ConfigParser.ConfigParser.
>> It implements add_section(self, section), which is also implemented on
>> ConfigParser.ConfigParser, which I want to call.
>> So, reducing the problem to the bare minimum, the class (with a useless
>> add_section that shows the problem):
>>
> The problem is that ConfigParser.ConfigParser is an old style class. It
> is in the standard library, so I have no clue why. For old style
> classes, you should directly call the ancestor class method.
> For new style classes it works just fine:
>
>
> class ConfigParser(object):
> def add_section(self, section):
> print section, "in ",self.__class__.__name__
>
> class MyConfig(ConfigParser):
> def add_section(self, section):
> super(MyConfig, self).add_section(section)
>
> m = MyConfig()
> m.add_section("blah")
I see, thank you.
class MyConfig(ConfigParser, object):
def add_section(self, section)
super(MyConfig, self).add_section(section)
seems to work and as expected. Is there anything wrong with it ?
--
Pupeno <pupeno at pupeno.com> (http://pupeno.com)
More information about the Python-list
mailing list