global name 'self' is not defined - noob trying to learn
mark.seagoe at gmail.com
mark.seagoe at gmail.com
Mon Mar 30 00:18:03 EDT 2009
Hi. So now I have this class that works to allow me to pass in my
reg_info struct. However when I try to make it part of my class it
gets an error "global name 'self' is not defined. I've never seen
this error before. If I comment out the line below 'self.reg_info =
reg_info" then the code runs... but I need to add stuff to this class,
and so I'm wondering why I can't use 'self' anymore?
from ctypes import Structure, c_byte, c_char
class REG_INFO(Structure):
_fields_ = [
('address', c_byte),
('message', c_char * 256)
]
class myclass(long):
def __new__(class_, init_val, reg_info):
print reg_info.message
self.reg_info = reg_info # <== Offending line
return long.__new__(class_, init_val)
#
# setup
my_reg = REG_INFO()
my_reg.address = 0xab
my_reg.message = 'hello world'
print 'TEST 1'
dog = 0x123456789ABCDEF0
print 'type(dog) = %s' % type(dog)
print 'dog val = 0x%016X' % dog
print 'TEST 2'
cat = myclass(0x55, my_reg)
print 'cat val = 0x%016X' % cat
print 'type(cat) = %s' % type(cat)
Thanks!
Mark
More information about the Python-list
mailing list