[Tutor] __init__ problem

Corran Webster cwebster@math.tamu.edu
Thu, 25 Mar 1999 10:38:02 -0600 (CST)

On 25 Mar, alan.gauld@bt.com wrote:
> Given:
> class Transaction:
>     def __init__(self):
>     	self.total = self.paid = self.change = 0
>     	self.GST = 0.07
>     	self.items = []
> class RentalTransaction(Transaction):
>     def __init__(self):
>     	Transaction.__init__(self)
>     	pass
> why do I get:
>>>> r = RentalTransaction()
> Traceback (innermost last):
>   File "<interactive input>", line 1, in ?
>   File "C:\Program Files\Python\Projects\transact.py", line 38, in __init__
>     Transaction.__init__(self)
> TypeError: unbound method must be called with class instance 1st argument

I copied and pasted the example and it works fine for me (Python 1.5.1
on Solaris), but I notice that you are indenting using both tabs and
spaces.  While the combination of tabs and spaces that appreared in you
message appears to be consistent (each singly indented line has 4
spaces, each doubly indented line has 4 spaces followed by one tab), it
might be worthwhile checking that the original version doesn't have an
additional tab somewhere which is causing a conflict.

In general it is a very bad idea to indent using spaces and tabs, use
one or the other, but not both together.  Unfortunately some editors can
be bad about automatically inserting them.  I'd recommend going through
and replacing all your tabs by spaces to ensure correct indentation,
and then seeing if it works.