Self Undefined Error
Andrew Bennetts
andrew-pythonlist at puzzling.org
Mon Jan 13 23:23:32 EST 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.
E.g.:
class Exploit:
def init(self):
pass
(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.)
-Andrew.
More information about the Python-list
mailing list