a couple of questions: pickling objects and strict types
mblume
foobar at invalid.invalid
Sat Apr 6 06:30:29 EDT 2013
Am Sat, 06 Apr 2013 02:37:31 +0000 schrieb Steven D'Aprano:
>>> [...]
>> def __init__(self):
>> self.events = {}
>> self.components = []
>> self.contents = []
>> self.uid = uuid4().int
>> self.events['OnLook'] = teventlet()
>>
>>
>> Basically events don't get initialized like I'd like after I depickle
>> objects.
>
>
> Correct, by default pickle does not call the __init__ method, it just
> reconstructs the instance. Basically, it takes a snapshot of the
> instance's internal state (the __dict__) and reconstructs from the
> snapshot.
>
> [...]
>
To the OP: Did you really mean
self.events['OnLook'] = teventlet()
as opposed to:
self.events['OnLook'] = teventlet
The first one executes teventlet and then assigns the result of the function to
self.events['OnLook']. The second one assigns the function teventlet to the dict
entry (presumably so that it will be called when the objct detects the 'OnLook'
event). Unless the teventlet() function returns itself a function, an 'OnLook'
event won't do anything useful during the remaining life time of the object, I think.
Regards
Martin
More information about the Python-list
mailing list