(relative) import trouble, sometimes it works, sometimes it doesn't...

S

Stef Mientki

hello,

I'm running Python 2.5 and want my programs to run at least under
Windows and Linux (preferable also Mac).
So I guess I should always use relative paths.

From most modules I can call a global function,
that should import a dictionary from path deeper than the module itself.
The import is done in the global function.
In that global function, I get the modules path by

SourceFile = sys._getframe(1).f_code.co_filename

now to be sure to succeed the import (at least I was thinking this would
always be successful :-(
I need to
1- add the path of the module to be imported to sys.path
(or do a dot import)
2- keep track of already done imports, to give a reload the next time
(or maybe always do an import followed by an reload ?)

Now what I don't understand is what relative path should I use in 1:
- relative to the main application
- relative to the working directory were I started the application
- relative to the current working directory
- relative to the module that is doing the import
- relative to the module that called the global function

I would be pleased if someone could enlighten me,
because this information is hard to find.

thanks,
Stef Mientki
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top