escribió:
I'm running Python 2.5 and want my programs to run at least underWhy don't you let the caller tell you its own location, using __file__?
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
The above code is too much magic for me.
now to be sure to succeed the import (at least I was thinking this wouldYes.
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 timeA reload is only required if the module was changed on disk and you want
(or maybe always do an import followed by an reload ?)
to get the later version.
Now what I don't understand is what relative path should I use in 1:Relative imports assume you are inside a *package*, and they're relative
- 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
to the current module location, each dot being one level above. See
http://www.python.org/dev/peps/pep-0328/
I would be pleased if someone could enlighten me,Yes. How import works is very poorly documented, unfortunately. You'll
because this information is hard to find.
have to dig into the various PEPs and the bug tracker.
--
Gabriel Genellina