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

Martin M. martinmichel at ame-electroplating.com
Thu Dec 15 04:05:16 EST 2005


Hi Heiko,

Thanks so much for your help! I just tested it and it works like a
charm!

****Test File 1****
-- main.py
#!/usr/bin python

from lib import being

being.location()

****Test File 2****
-- being.py
#!/usr/bin/python

import os

def location():
    print os.path.abspath(__file__)
****
results in:
martin% python main.py
/Volumes/CodeIsland/Projects/glashaus/glashaus0.1a/lib/being.pyc

Now I can use os.path.split() to get the parent directory and
os.path.join() to target my AppleScript file.

Thanks again!

Martin M.




More information about the Python-list mailing list