finding origin of names

Jeff Epler jepler at unpythonic.net
Sat Jun 7 22:03:05 EDT 2003


On Sat, Jun 07, 2003 at 06:28:01PM +0100, Robin Becker wrote:
> In article <2259b0e2.0306070843.4ac68402 at posting.google.com>, Michele
> Simionato <mis6 at pitt.edu> writes
> ......
> >
> >If I understand correctly you want inspect.getsource or inspect.getmodule
> >or inspect.getsourcefile or something like that ...
> >
> >
> >                                Michele
> yes that works for functions and classes containing a method, but not
> instances.

.. then do something nasty in the instance __init__, such as 
	def __init__(self):
		self.createdfrom = sys._getframe(1).f_globals['__name__']
that'll store the module name that the calling function was in.  It won't
tell you want name it was first stored to, there's no way to get that (in
fact, it might never be given a name, or might be given a name by the
one-level-up caller instead of the direct caller.

Jeff





More information about the Python-list mailing list