A simpler super.

Gustavo Niemeyer niemeyer at conectiva.com
Fri Apr 12 10:34:14 EDT 2002


> def Super(yourself):
>     if isinstance(yourself, type): # for classes
>         return super(yourself, yourself)
>     return super(yourself.__class__, yourself)

I had the same idea a while ago. This can't be done. Think about what
happens here:

class A:
	def __init__(self):
		pass
class B(A):
	def __init__(self):
		Super(self).__init__(self) # <-- problem
class C(B):
	def __init__(self):
		Super(self).__init__(self)

In this case, you'll get a loop, because self.__class__ is C, no matter
where it is called.

-- 
Gustavo Niemeyer

[ 2AAC 7928 0FBF 0299 5EB5  60E2 2253 B29A 6664 3A0C ]





More information about the Python-list mailing list