|
Alrighty o! i had a look at your tutorial and have created the classes the way that are supposed to look. so what i need help with is how to add an attribute "displayinfo" which will display the details of my three objects.
#!/usr/bin/python
# your 3 Classes are: Publication, Book and Disc # 1st Class is Publication with Special Class (object)
class Publication: def __init__ (self,pubtitle,pubgenre): self.title = pubtitle self.genre = pubgenre self.pubID = 'xxxx' return
class Book(Publication): def __init__ (self,pubtitle,pubgenre,bookpages): Publication.__init__(self,pubtitle,pubgenre) return
class Disc(Publication): def __init__ (self,pubtitle,pubgenre,bookpages): Publication.__init__(self,pubtitle,pubgenre) return
def test():
book1=Book('Lord of the Kings','Science Fantasy',987) book2=Book('Love Never Dies','Romance',176) book3=Book('Ten to Midnight','Crime Thriller',235) disc1=Disc('Hello Dolly','Comedy',115) disc2=Disc('Lord of the Rings','Science Fantasy',542) disc3=Disc('Needles and Pins','Medical Reference',120)
print '\nTesting...\n' book1.displayInfo() book2.displayInfo() book3.displayInfo()
disc1.displayInfo() disc2.displayInfo() disc3.displayInfo() if __name__=='__main__': test() print'\nHave a nice day'
results are!!!:
Testing...
Traceback (most recent call last): File "C:/Documents and Settings/Mike/Desktop/Python work/experiment.pyw", line 62, in <module> test() File "C:/Documents and Settings/Mike/Desktop/Python work/experiment.pyw", line 52, in test book1.displayInfo() AttributeError: Book instance has no attribute 'displayInfo' >>>
This post has been edited by mjsinpl: 14 Oct, 2007 - 09:28 AM
|