[Tutor] identifying the calling module/function

Andreas Kostyrka andreas at kostyrka.org
Fri Mar 7 15:02:49 CET 2008


There are basically a number of things you might want:

1.) sys.argv[0]
2.) __main__.__file__
3.) sys._getframe

The first two will tell which script is the main program. The last one
will tell you which function has called you.

But as Kent has pointed out, this is rarely a good idea. Actually, it's
almost never a good idea, and in most cases it's a really bad idea,
designwise.

Andreas


Am Freitag, den 07.03.2008, 14:16 +0100 schrieb tetsuo2k6 at web.de:
> Hello Tutor!
> 
> I am building a couple of scripts to manage a database for our company. 
> The projects name is 'dgf'. As a lot of the functionality is used in 
> more than one of these scripts, I moved this functionality to a module 
> (dgf.py). It has several functions now.
> 
> Question: Is there an easy way to determine inside dgf.py where the 
> function call came from?
> 
> dgf.py:
> 
> def yetanotherfunction():
> 	"""Edit Me!"""
> 	if <function call came from script.py>:
> 		...
> 
> Something like that?
> 
> 
> 
> 
> Regards
> -paul
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://mail.python.org/pipermail/tutor/attachments/20080307/796b3dd0/attachment.pgp 


More information about the Tutor mailing list