A light in Maya has an attribute Use Color Temperature
, which is a checkbox, when I toggle it, a function is called inside Maya to actually do the work behind the scene. Unfortunately the function address <function callback at 0x0000000051CD7DD8>
is printed out instead of it's name. I don't know which function is executed when clicking the checkbox. Is there any way of converting this address to python function object or can I print the actual name of the function using this memory address?

- 3,885
- 24
- 36
-
This probably means a function called `callback` is called. I'd look for `def callback(...):` – Reut Sharabani Jan 05 '15 at 10:01
-
`callback` is the name. – Klaus D. Jan 05 '15 at 10:01
2 Answers
This means a function named callback
is called.
I'd look for def callback(...):
in the corresponding code file and see what it does.
To re-produce your output all that's needed is a function with the name callback
:
>>> def callback():
... print "My name is Reut Sharabani"
...
>>> cb = callback
>>> cb
<function callback at 0x7f182f3ca6e0>
If you want to programmatically get a function's name:
>>> cb.__name__
'callback'
If you want to know more about it you can even disassemble it using dis
and it's code object:
>>> import dis
>>> dis.dis(cb.__code__)
2 0 LOAD_CONST 1 ('My name is Reut Sharabani')
3 PRINT_ITEM
4 PRINT_NEWLINE
5 LOAD_CONST 0 (None)
8 RETURN_VALUE

- 30,449
- 6
- 70
- 88
This seems like pure evil and to be honest, I think you can/should use callback
instead. But for reference, apparently you can use the garbage collection module gc
to get the object from that id
.
Found on this SO response (you really can find anything on SO...):
import gc
def objects_by_id(id_):
for obj in gc.get_objects():
if id(obj) == id_:
return obj
raise Exception("No found")
I believe you need to coerce that number into an int
representation because id(obj)
returns an int
rather than hex
.
NB this may have some weird race conditions with object ids potentially being recycled after an object is deleted.
-
Python automatically converts hex to int. Try passing the hex to `objects_by_id` – qurban Jan 05 '15 at 13:11