View Single Post
Old Jun 3rd, 2006, 9:20 AM   #5
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by Sane
That's excellent. Thanks. So does that work by inheriting the class "int"?
Yep. You're essentially extending integer class by adding some extra functionality onto it.

Quote:
Originally Posted by Sane
I've only worked with class inheritance for wxPython and it looks like fun. Do you have any quick programming challenges you can think of that involve making inherited classes?
How about: create a new list object such that len, map and filter are methods of the class. e.g.
mylist = advanced_list(1, 2, 3, 4, 5)
print mylist.len()
print mylist.filter(lambda x : (x % 2) == 0)
print mylist.map(lambda x: x * 2)
Metaclasses, types, and the __new__ method are also some interesting topics to study. For instance, did you know that the type method can also be used to construct new classes dynamically?
Arevos is offline   Reply With Quote