Python 3.0 classes?

Started by
2 comments, last by swiftcoder 15 years, 6 months ago
I have recently been reading the most recent Byte of Python that is edited for python 3.0 and I have had some problems with it's example for a simple class. Here is the coding


class Person():
    def sayHI(self):
            print('Hello,how are you?')


p = Person()
p.sayHi()

I keep getting this error. Traceback (most recent call last): File "C:\Users\Eric\Desktop\Python Progs\Person Class.py", line 8, in <module> p.sayHi() AttributeError: 'Person' object has no attribute 'sayHi' can anyone tell me what I am doing wrong?
---------------------------------------------------------------------------------------Exercise, eat right and be the best you can be!Translation: Play video games for finger streangth and eat lots of hot pockets to be at top programming efficiency.
Advertisement
Python is case sensitive. sayHi is not the same as sayHI.
OH MY GOD!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!. I can't belive I didn't catch that!>< I feel like an idiot. I checked and checked and I couldn't tell that a stinkin 'i' was screwing me over. :(. Thanks for pointing that out.
---------------------------------------------------------------------------------------Exercise, eat right and be the best you can be!Translation: Play video games for finger streangth and eat lots of hot pockets to be at top programming efficiency.
Quote:Original post by steveworks
can anyone tell me what I am doing wrong?
Python is case-sensitive. You are trying to call a method 'sayHi', when the method is actually called 'sayHI'.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

This topic is closed to new replies.

Advertisement