Self Undefined Error

Bjorn Pettersen BPettersen at
Tue Jan 14 06:10:35 CET 2003

> From: Brent Bailey [mailto:brb5548 at] 
> I am new to python and I must not understand how to make correct


> declerations.  Does anyone have any idea why I get, 
> NameError: "self" is not
> defined, for the following code.

When posting a problem like this, it is very useful (i.e. easier for us
to figure out) if you also include the traceback that Python printed
when it encountered the error.

In this case, I'm guessing it's the line:

  if self.s in r:

which looks like it should be indented to be inside your attack method.

It also looks like you don't quite understand how to define classes, you
might want to re-read
Ask more questions if any of that is unclear.

-- bjorn

More information about the Python-list mailing list