[Tutor] Classses

alan.gauld@bt.com alan.gauld@bt.com
Fri, 24 May 2002 09:47:26 +0100


> I am reading Alan Gauld 

I wondered what that strange sensation was... ;-)

> class Address:=0D
>            def _init_(self,Hs,Town,Zip)=0D
>                   self.Hs_Number=3DHs=0D
>                   self.Street=3DSt=0D
>                   self.Town=3DTown=0D
>                   self.Zip_Code=3DZip=0D

Thats two underscores each end of init, not one.

This is a common convention in Python for 'magic' function 
names.

There are a couple of footnotes in the book but if I ever do a 
2nd edition I'll elevate them to the main text since you 
aren't the first to miss them!

> TypeError: this constructor takes no arguments=0D

This is because Python doesn't recognise your init as a 
constructor so is using the default one which, as it says, 
takes no arguments...

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld