Wo ist das Modul importiert wird?

Angenommen, ich habe zwei Python-Module und path_b ist in der import-Pfad:

# file: path_b/my_module.py
print "I was imported from ???"

#file: path_a/app.py
import my_module

Ist es möglich zu sehen, wo das Modul importiert wird? Ich möchte eine Ausgabe wie "ich war importiert aus path_a/app.py" wenn ich starte app.py (da brauche ich den Namen der Datei).

Edit:
Zum besseren Verständnis; ich könnte schreiben:

# file: path_b/my_module.py
def foo(file):
    print "I was imported from %s" % file

#file: path_a/app.py
import my_module
my_module.foo(__file__)

Also die Ausgabe wäre:

$> python path_app.py
I was imported from path_a/app.py

InformationsquelleAutor der Frage svenwltr | 2011-08-22

Schreibe einen Kommentar