[Tutor] Class Construction question

Bob Gailer ramrom@earthling.net
Mon Nov 11 19:22:01 2002


>class Person:
>
>     def setPhone(self, string):
>         self.PhoneNumber = string
>
>         def setName(self, string):
>                 self.FirstName = string
>
>     def getName(self):
>         return self.FirstName
>
>     def getPhoneNumber(self):
>         return self.PhoneNumber

Fix the indentation so def setName is indented the same as the other defs, 
e.g.:

>     def setPhone(self, string):
>         self.PhoneNumber = string
>
>     def setName(self, string):
>         self.FirstName = string

The way you have it should produce an error similar to:

Traceback (most recent call last):
   File "P:\Python22\test14.py", line 17, in ?
     testing.setName("Chris")
AttributeError: Person instance has no attribute 'setName'

Is that what you're getting, or what does "hang" mean?

Bob Gailer
170 Forsythe Rd
Nederland CO 80466
303-442-2625