global name 'self' is not defined - noob trying to learn

MRAB google at mrabarnett.plus.com
Mon Mar 30 18:25:06 CEST 2009


mark.seagoe at gmail.com wrote:
> Here again is example:
> 
> 
> from ctypes import *
> 
> class REG_INFO(Structure):
>     _fields_ = [
>         ('address', c_ubyte),
>         ('message', c_char * 256),
>         ('size', c_ubyte)
>         ]
> 
> class myclass(object):
> #
>     # def __new__(class_, init_val, size, reg_info):
>     def __init__(self, init_val, size, reg_info):
> 
>         # self = object.__new__(class_)
>         self.reg_info = reg_info
>         print self.reg_info.message
>         self.val = self

Don't you really mean:

         self.val = init_val

>         self.size = reg_info.size
>         print 'address = 0x%02X' % self.reg_info.address
>         # return self
[snip]




More information about the Python-list mailing list