10

Python interpreter is showing NameError on using Object.

>>> class test(Object): pass
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'Object' is not defined

Python version is 2.7.3.

I haven't been able to remove this error. Am I missing something here?

2 Answers 2

18

object must be lower-case. Try

>>> class test(object): pass

In Python 3.x, you can also just leave it out:

>>> class test: pass

(In 2.x, you should not do that until you are ready to face the monstrosity of classic classes)

Sign up to request clarification or add additional context in comments.

Comments

-1

yes,it is need to lower-case:

#define class

class Student(object):

print('start')

# name & score

def _init_(self, name, score):
        self.name = name
        self.score = score

    def printScore(self):
        print('%s: %s' % (self.name, self.score))

    def set_score(self, value):
        if not isinstance(value, int):
            raise ValueError('score must be an Integer')
        if value < 0 or value > 100:
            raise ValueError('score must between 0 ~ 100!')

        self.score = value

    def get_score(self):
        return self.score

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.