Self Undefined Error

Andrew Bennetts andrew-pythonlist at
Tue Jan 14 05:23:32 CET 2003

On Tue, Jan 14, 2003 at 04:05:09AM +0000, Brent Bailey wrote:
> 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.
> import socket
> import struct
> import select
> class Exploit:
> def init(self):
>         pass

Methods of a class need to be indented, so that they are "inside" the class.

class Exploit:
    def init(self):

(Note also that the constructor for a class in python is __init__, not init,
and if it doesn't do anything, may be omitted entirely.)


More information about the Python-list mailing list