I am shuffling my way through 'Python in easy steps' I have reached the section on 'Classes' and cannot make the tutorials work. I have tried several variations on the attached code without success. The first program Bird.py which sets up the class does not give any errors but running instance.py always errors. 'Bird has no attribute _doc_' is an example of the first error.
Can anyone through any light/knowledge my way since I am getting frustrated. Code below.
Malcolm Smith
#!/C:\python3 #Bird.py
# Declare a new class with descriptive string class Bird: """A base class to define bird properties."""
#Declare and initialise a class variable with integer value zero count=0
#Define initialiser class method to initialise instance variable & increment class variable def _init_(self, chat): self.sound = chat Bird.count+= 1
# Add class method to return value of instance variable when called #and save to file def talk(self):
return self.sound =================================================================== #!/C:\python3 #instance.py
#Make features of class file available then display its document #string from Bird import* print('\nClass Instances Of:\n',Bird._doc_)
# statement to create an instance of the class & pass string value to #its instance variable polly = Bird('Squawk,squawk!')
#Display this instance variable value & call class method to display #common class variable value print('\nNumber Of Birds:',polly.count) print('Polly Says:',polly.talk())
#Create second instance of class passing different string to instance #variable harry=Bird('Tweet, tweet!')
#Display instance variable value and call class method to display #common class variable value print('\nNumber Of Birds:',harry.count) print('Harry Says:', harry.talk())