[Tutor] NameError: <nothing> is defined

brandon w thisisonlyatest at gmx.com
Wed Jul 20 04:37:16 CEST 2011


Hi
I am running Linux with Python 2.6.6. I have done lists, tuples, 
dictionaries, etc. Now I want to move on to creating a "class". I keep 
getting an error for everything I try. Here is the error: *

NameError: name 'MyClass' is not defined*

I had originally tried to create my own class by watching some video 
tutorials. Nothing worked. Then from the python2.6-doc documentation I 
just decided to copy and paste from the documentation.

*class  MyClass:
     """A simple example class"""
     i  =  12345
     def  f(self):
         return  'hello world'*


*>>> MyClass
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
NameError: name 'MyClass' is not defined*

Still the same error. What am I doing wrong?
I tried this in gnome-terminal in a Python shell and using IDLE.

First I do: *import myscript.py
*(no errors)*
*
Then I run: *MyClass*
(error)

I try:  n = *MyClass()*
(error)

I try:
*MyClass.n
n.MyClass
i.MyClass
MyClass.i
i.MyClass()
f.MyClass
f.MyClass()*

(nothing but errors)



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110719/fb8d6283/attachment.html>


More information about the Tutor mailing list