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

Martin M. martinmichel at ame-electroplating.com
Thu Dec 15 02:26:38 EST 2005


Hi,

I have the following question: How can an imported module see/find the
path to itself?

Background: From my main script I import a module which needs a file
(AppleScript) located in the same directory as the imported module.
What I do not want is to tell the module the location of the
AppleScript file by passing this information from the main script,
because I want my imported module to be independent from the main
script.

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?

I hope you understand my problem and I appreciate any helpful answers!

Happy scripting!

Martin

P.S.: Background-background: I try to build myself a library of Python
scripts, which are getting a lot of infro from AppleScripts which
reside in the same directoty (e.g. usrdrs.py & usrdrs.scpt, usrdrs.py
is reading/executing usrdrs.scpt and returning the gathered info).




More information about the Python-list mailing list