Register • FAQ • Memberlist • Usergroups • Tutorials Point • Log in

| Page 1 of 1

I NEED HELP URGERNTLY BEFORE I LOSE INTEREST
Author | Message
--- | ---
cocman Joined: 27 Jul 2011 Posts: 2 | 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
Wed Jul 27, 2011 10:36 pm |
tutorialspoint Site Admin Joined: 27 Apr 2007 Posts: 134 | 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.
Thu Jul 28, 2011 4:07 am |
cocman Joined: 27 Jul 2011 Posts: 2 | Post Confirmation Thanks for your post. This post will be reviewed by webmaster and will be online very soon.!
Thu Jul 28, 2011 4:15 pm |

Display posts from previous: |

| 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

Powered by phpBB © phpBB Group Design by Vjacheslav Trushkin for phpBBStyles.com