>> def spam():
... print("top secret function")
...
>>> print(spam)
<function spam at 0x7feccc97fb78>
>>> spam = "spam"
So I lose the reference to spam function. Can I get it back from that memory address: 0x7feccc97fb78?
>>> orig_spam_function = get_orig_func_from_memory_address("0x7feccc97fb78")
Edit (responding to thefourtheye):
Sorry for the lousy question, consider this case:
>>> from collections import defaultdict
>>> d = defaultdict(spam)
>>> d
defaultdict(<function spam at 0x7f597572c270>, {})
So the function is not garbaged collected yet. Can I recover it? Of course, in this case, you can use default_factory attribute.
>>> d.default_factory
<function spam at 0x7f597572c270>
But imagine defaultdict without default_factory attribute.