[Tutor] class again
fleet@teachout.org
fleet@teachout.org
Sun, 2 Dec 2001 15:15:16 -0500 (EST)
I have followed the example in Core Python Programming (pg 403) re;
AddrBookEntry class. If I type it in at the interactive Python prompt
everything works fine. When I try to put the class in a file
(addrbook.py) and 'import addrbook' I get no complaints; but I can't
instantiate the class. (Ie, john = AddrBookEntry('John Doe',
'405-555-1212'). I get NameError: AddrBookEntry.
Where did I fall off the track?
Thanks,
- fleet -
So you don't have to look it up, here's the class:
class AddrBookEntry:
'address book entry class'
def __init__(self, nm, ph):
self.name = nm
self.phone = ph
print 'Created instance for:', self.name
def updatePhone(self, newph):
self.phone = newph
print 'Updated phone# for:', self.name