local variable referenced before assignment
Robert Kern
robert.kern at gmail.com
Mon Apr 5 13:20:41 EDT 2010
On 2010-04-05 12:08 PM, John Nagle wrote:
> Alf P. Steinbach wrote:
>
>> Best is however to recognize that you have some state (your variable)
>> and some operations on that state (your callback), and that that is
>> what objects are all about. I.e. wrap your logic in a class. Then
>> 'lastModifiedTime' becomes an instance attribute, and 'handler'
>> becomes a method.
>>
>> It doesn't matter that there will only ever be one object (instance)
>> of that class.
>>
>> Classes were meant for just this sort of thing, state + operations.
>
> Yes. Functions with persistent state are generally a bad idea.
>
> Unfortunately, the "signal" module requires a callback parameter
> which is a plain function. So you have to send it a function,
> closure, or lambda.
Does it? The docs say that it just needs a callable object. An instance with a
__call__() method would suffice.
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-list
mailing list