Relative Imports, why the hell is it so hard?
gagsl-py2 at yahoo.com.ar
Wed Mar 25 22:21:58 CET 2009
En Tue, 24 Mar 2009 21:57:12 -0300, Istvan Albert
<istvan.albert at gmail.com> escribió:
> On Mar 24, 3:16 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
>> Did you know, once a module is imported by the first time
> yeah yeah, could we not get sidetracked with details that are not
> relevant? what it obviously means is to import it in all of your
> modules that need to access to relative paths
Uh? You posted a module containing a function and some code that modifies
sys.path. I imagine you are interested in those side effects in sys.path
-- which will only happen the first time it is imported. Isn't it relevant?
>> I don't understand, how is this supposed to help relative imports?
> That's only because you have not had to deal with the problem that it
But I had to deal with the problem that it *creates*, even before relative
imports existed, and it's a lot worse.
>> Bindly inserting directories into sys.path can easily confuse the
>> import systemn
> confuse the import system? what the heck does that mean? You either
> have a path in the sys.path or not. FWIW it is far cleaner than doing
> a relative import that does not work correctly.
Others have posted the way to execute modules inside a package. For the
problem of adding random directories to sys.path, see:
More information about the Python-list