Q: scope of module functions

Chris Liechti cliechti at gmx.net
Sat Jun 8 13:37:46 EDT 2002

"Frank Sonnenburg" <sonnenbu at informatik.uni-bonn.de> wrote in 
news:adte4c$nu8$1 at f1node01.rhrz.uni-bonn.de:
> a little tricky problem (at least from my point of view); given module
> # i need "fct" and some other from module "UTILS"
> from UTILS import *
> fct()
> # END of module CALLER
> Now, inside fct(), how do i determine the module - in this case CALLER -
> from where fct() was called?

i think __name__ can help in this case but not in the one below.
but are you sure that you wan't t do this? a function that behaves 
differently depending on the namespace gives very hard times debugging...

a cleaner solution would be to create an class that contains fct and each 
module that uses it can create its own object.

if you can say what you want to achieve, we might give you a more specifuc 

> Even concerning cases like (continuation of example):
> # Now we are in __main__
> import CALLER
> fct_in_main = CALLER.fct
> fct_in_main()

Chris <cliechti at gmx.net>

More information about the Python-list mailing list