M
mk
Hello everyone,
I'm storing functions in a dictionary (this is basically for cooking up
my own fancy schmancy callback scheme, mainly for learning purpose):
.... return "f2 " + arg
........ return "f1" + arg
....
Well, neat. Except if I change function definitions now, old functions
are called. And rightly:
.... return "NEW f1 " + arg
....<function f1 at 0xb7f0b994>
The address of function f1 has obviously changed on redefinition.
Storing value copies in a dictionary on assignment is a reasonable
default behaviour.
However, in this particular case I need to specifically store
_references to objects_ (e.g. f1 function), or should I say _labels_
(leading to objects)?
Of course, I can basically update the dictionary with a new function
definition.
But I wonder, is there not a way _in general_ to specifically store
references to functions/variables/first-class objects instead of copies
in a dictionary?
I'm storing functions in a dictionary (this is basically for cooking up
my own fancy schmancy callback scheme, mainly for learning purpose):
.... return "f2 " + arg
........ return "f1" + arg
....
['f11', 'f2 2']>>> a={'1': f1, '2': f2}
>>>
>>> [ x[1](x[0]) for x in a.items() ]
Well, neat. Except if I change function definitions now, old functions
are called. And rightly:
.... return "NEW f1 " + arg
....<function f1 at 0xb7f0b994>
The address of function f1 has obviously changed on redefinition.
Storing value copies in a dictionary on assignment is a reasonable
default behaviour.
However, in this particular case I need to specifically store
_references to objects_ (e.g. f1 function), or should I say _labels_
(leading to objects)?
Of course, I can basically update the dictionary with a new function
definition.
But I wonder, is there not a way _in general_ to specifically store
references to functions/variables/first-class objects instead of copies
in a dictionary?