Return name of caller function?
Matthew Peter
survivedsushi at yahoo.com
Wed Jun 27 20:07:08 EDT 2007
> The code below doesn't do the trick for you?
>
> #!/usr/bin/python
> import inspect
>
> def master():
> print "I am the master"
> slave()
>
> def slave():
> stack = inspect.stack()
> caller = stack[1][3]
> print "I am the slave; my caller was %s" % caller
>
> def main():
> master()
>
> if __name__ == '__main__':
> main()
[..]
Yes. That does work. I was testing with an aliased instance of function which was
returning <module>
>>>a = slave
>>>print a()
<module>
Is regex'ing stack[1][4] the only way to return 'a' in this instance?
____________________________________________________________________________________
Be a PS3 game guru.
Get your game face on with the latest PS3 news and previews at Yahoo! Games.
http://videogames.yahoo.com/platform?platform=120121
More information about the Python-list
mailing list