www.tutorialspoint.com Forum Index
Register FAQMemberlistUsergroupsTutorials PointLog in
Reply to topic Page 1 of 1
I NEED HELP URGERNTLY BEFORE I LOSE INTEREST
Author Message
Reply with quote
Post I NEED HELP URGERNTLY BEFORE I LOSE INTEREST 
I an new to programming, I progressed to oop in python using different books but when I get to oop things go very wrong. then I went on-line but but I still get errors when I run an example code which ran perfectly on their system. For example this code I found on tutorialspoint:


class Employee:
'common base class for all employees'
empCount=0
def displayCount(self):
print "Total employee %d"%Employee.empCount

def displayEmployee(self):
print "Name:",self.name,'salary:',self.salary

emp1= Employee()
emp2= Employee()
emp1.displayEmployee()
emp2.displayEmployee()
print "Total employee(s)%d"%employee.empCount

when they ran it it printed on the screen this:

Name : Zara ,Salary: 2000
Name : Manni ,Salary: 5000
Total Employee 2


but if I run the same code I get this:

>>>
Name:
Traceback (most recent call last):
File "J:\employee.py", line 20, in <module>
emp1.displayEmployee()
File "J:\employee.py", line 14, in displayEmployee
print "Name:",self.name,'salary:',self.salary
AttributeError: Employee instance has no attribute 'name'

this same error is produced any time I run any python code on oop
I mean is OOP not for everyone?
because I am sick and tired of this rubbish

View user's profile Send private message
Reply with quote
Post  
I think you are using different python version. I'm using Python 2.4.3 and it is working fine. Just check the syntax with new version.


_________________
Moderator, TP
Keep visiting and share this site with your friends.
View user's profile Send private message Send e-mail
Reply with quote
Post Post Confirmation 
Thanks for your post. This post will be reviewed by webmaster and will be online very soon.!

View user's profile Send private message
Display posts from previous:
Reply to topic Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum