[Tutor] Newbie problems

Glen Wheeler wheelege@tsn.cc
Thu, 28 Jun 2001 19:03:05 +1000


> Hello List,

  Hi! :)

>
> I'm trying to learn Python but when using one of the examples on
> http://www.crosswinds.net/~agauld/ i get an error.
>
> the example:
>
> >>>class Address:
> ...   def __init__(self, Hs, St, Town, Zip):
> ...     self.HsNumber = Hs
> ...     self.Street = St
> ...     self.Town = Town
> ...     self.ZipCode = Zip
>
> Addr = Address(7,"High St","Anytown","123 456")
>
>
> which gives the following error:
> ---
> Traceback (innermost last):
>   File "<stdin>", line 1, in ?
> NameError: Address
> ---
> Any help would be greatly appreciated.
>
>

  Well, from first look nothing appears wrong.  A NameError means that
Python can't find the object your talking about - in this case it's Address,
and that's the class.  How are you running this?  Here is my attempt at the
interepreter...

>>> class Address:
...  def __init__(self, Hs, St, Town, Zip):
...   self.HsNumber = Hs
...   self.Street = St
...   self.Town = Town
...   self.ZipCode = Zip
...
>>> Addr = Address(7,"High St", "Anytown", "123 456")
>>> print Addr.HsNumber
7
>>>  ## etc

  Can you try again, and if you still have trouble post again in more
detail?

  Thanks,
  Glen.