Introspection & Python Functions

Mike Dean klaatu at evertek.net
Fri Dec 13 15:41:35 EST 2002


I was just playing around with some introspection in Python, and noticed
something (I think this has probably been commented on before, but
anyway...).  It appears there is no way for a function to access itself
besides, effectively, globals()['functionname'].  Why?  What happens to
recursion if some clever (or otherwise) code renames the function, then
repoints its old name to something else?  Suddenly, the function is
unable to fulfill its destiny.  And, it appears, the same goes for
classes (except such a thing is not needed there, as there are the
__new__ and __init__ methods).

So, is there something I am missing?  Or, if not, why has such a thing
missing?  Granted, I can't envision many useful scenarios for such a
thing (particularly now that statically nested scopes allow protection
for recursive functions by making them inside outer wrappers), but it
seems that it is a hole in Python's introspection.

Thoughts?

-Mike



More information about the Python-list mailing list