Simply Jonathan

Extending classes in Python

I tested today, and found that you can actually extend a class, on itself. Not just by using setattr(), but also by creating a new class:

>>> class bar:
...  def monkey(self):
...   print 'neat'
>>> class bar(bar):
...  def horse(self):
...   print 'sweet'
>>> bar().monkey()
>>> bar().horse()

Again, this might be in the manual, I just didn’t know of it until some ten minutes ago.

This is Simply Jonathan, a blog written by Jonathan Holst. It's mostly about technical topics (and mainly the Web at that), but an occasional post on clothing, sports, and general personal life topics can be found.

Jonathan Holst is a programmer, language enthusiast, sports fan, and appreciator of good design, living in Copenhagen, Denmark, Europe. He is also someone pretentious enough to call himself the 'author' of a blog. And talk about himself in the third person.