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 4 h 48 m 37 sec
Reputation Power: 65
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 12.3 (home desktop, laptop, work desktop), Ubuntu 12.04 LTS (mini laptop), Debian GNU/Linux 7.0 (server), Mythbuntu 12.04 LTS (HTPC), Bodhi Linux 2.0 & Windows 7 Ultimate (test desktop), FreeBSD 9.1 (test server)