global name 'self' is not defined - noob trying to learn
Scott David Daniels
Scott.Daniels at Acm.Org
Mon Mar 30 02:09:51 EDT 2009
mark.seagoe at gmail.com wrote:
> On Mar 29, 9:52 pm, Chris Rebert <c... at rebertia.com> wrote:
>> On Sun, Mar 29, 2009 at 9:18 PM, <mark.sea... at gmail.com> wrote:
>>> ...
>> ... Also, you shouldn't use `class_ ` as the name of the first argument to
>> __new__(). Use `cls` instead since that's the conventional name for
>> it.
Actually, according to PEP 8, class_ is the preferred name.
>> My best guess as to what you're trying to do is (completely untested):
>> class myclass(long):
>> def __new__(cls, init_val, reg_info):
>> print reg_info.message
>> instance = long.__new__(cls, init_val)
>> instance.reg_info = reg_info
>> return instance
Normally, these changes are done in the __init__ phase (post-instance
creation), so you might go for something like:
class myclass(long):
def __new__(class_, init_val, reg_info):
return long.__new__(class_, init_val)
def __init__(self, init_val, reg_info):
self.reg_info = reg_info
--Scott David Daniels
Scott.Daniels at Acm.Org
More information about the Python-list
mailing list