Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python showing error - name 'Object' is not defined

Tags:

python

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?

like image 380
db42 Avatar asked Jul 16 '12 18:07

db42


People also ask

How do you define a name error?

What is a NameError? A NameError is raised when you try to use a variable or a function name that is not valid. In Python, code runs from top to bottom. This means that you cannot declare a variable after you try to use it in your code.

Why does it say variable is not defined?

This error has the following cause and solution: You used an Option Explicit statement to require the explicit declaration of variables, but you used a variable without declaring it. Explicitly declare the variable, or change the spelling of the variable to match that of the intended variable.


1 Answers

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)

like image 61
phihag Avatar answered Sep 29 '22 06:09

phihag