Instructions in book don't work

A.A andtherewaswater at yahoo.com
Thu Jan 10 02:09:16 EST 2002


Dan,

The code should be:

>>> class Address:
     # Note the TWO underscores
...  def __init__(self, Hs, St, Town, Zip):
...     self.Hs_Number = Hs
...     self.Street = St
...     self.Town = Town
...     self.Zip_Code = Zip

Regards,

A.A.

> Dan Hamm wrote:
> 
> This is my very first attempt at using a newsgroup, so please bear
> with me. I am totally new to programming, and picked up the book "Lean
> to Program Using Python" by Alan Gauld. The problem I am trying to
> solve is this:
> 
> On page 51 the author shows demonstration code for setting up a class
> -
> 
> >>> class Address:
> ...  def _init_(self, Hs, St, Town, Zip):
> ...     self.Hs_Number = Hs
> ...     self.Street = St
> ...     self.Town = Town
> ...     self.Zip_Code = Zip
> 
> Then follows it up with the instructions to type in the following -
> 
> >>> addr = Address(7,"High St.","Anytown","12345")
> >>> print addr.Hs_Number, addr.Street
> 
> My problem is when I type the first line of the second set of
> instructions (addr = Address(7, ...) I get the following error -
> 
> Traceback (most recent call last):
>   File "<interactive input>", line 1, in ?
> TypeError: this constructor takes no arguments
> 
> I've checked to make sure I copied exactly what was in the book, but
> it just doesn't seem to work. Can anyone tell me where I went wrong?



More information about the Python-list mailing list