Deprecate self

s713221 at student.gu.edu.au s713221 at student.gu.edu.au
Thu Apr 19 06:36:48 EDT 2001


Dave LeBlanc wrote:

> I was going to mention super, but given the multiple inheritance
> nature of Python, it wouldn't work.

If you want super functionality, a poster a year or so ago, submitted
this little hack for a situation where he wanted to use a derived class
with multiple base classes, but without having to retype dozens of lines
of code.

class friendly:
	def __init__(self):
		print "Hello"
class friendlier(friendly):
	def __super(self):
		return friendly
	def __init__(self, name):
		self.__super().__init__(self)
		print name

As long as you've only got single inheritance, or are only interested in
the first class, you can automate it as follows:

class friendlier(friendly):
	def __super(self):
		return self.__class__.__bases__[0]

Useful in some situations,

Joal Heagney/AncientHart



More information about the Python-list mailing list