Self-awareness of imported modules? Do they know where they live?

Heiko Wundram modelnine at
Thu Dec 15 08:52:02 CET 2005

Martin M. wrote:
> So how can I do this? In AppleScript I would try something like "path
> to me", but this does not work for imported scripts in AppleScript, as
> you then only get the path to the main script. But can this be done in
> Python? Can modules know where they are currently located, where they
> live? Can they be self-aware?

Yes, they can be:

modelnine at phoenix ~ $ cat
import os

print os.path.abspath(__file__)
modelnine at phoenix ~ $ python
modelnine at phoenix ~ $


--- Heiko.

More information about the Python-list mailing list