469,898 Members | 1,533 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

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

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
Oct 18 '08 #1
0 1030

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Frans Englich | last post: by
3 posts views Thread by tsteinke | last post: by
18 posts views Thread by Nak | last post: by
1 post views Thread by geoffblanduk_nospam | last post: by
reply views Thread by Anders J. Munch | last post: by
reply views Thread by Echo | last post: by
9 posts views Thread by rbygscrsepda | last post: by
reply views Thread by Kay Schluehr | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.