Discuss Simple inheritance (newbie) in the Python Programming forum on Dev Shed. Simple inheritance (newbie) Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
Time spent in forums: 1 Week 18 h 35 m 57 sec
Reputation Power: 66
Originally Posted by imchi
When I execute this code, I get "TypeError: must be type, not classobj".
Because in Python 2, not specifying the base class means you are using the old class system.
To fix in Python 2, use:
For the rest of your code, it (almost) works in Python 3 as is. However, you cannot use multiple definitions for __init__ (or any other function for that matter); instead, you should write the definition so that it fits all uses:
def __init__(self, amount=0):
self.amount = amount
My armada: openSUSE 13.1 (home desktop, home laptop), Ubuntu 13.04 (work laptop), FreeBSD 9.2 (server), Mythbuntu 12.04 LTS (HTPC), Bodhi Linux 2.0 & Windows 7 Ultimate (test desktop), Android 4.1.2 (tablet)