Relative Imports, why the hell is it so hard?

Carl Banks pavlovevidence at gmail.com
Wed Mar 25 22:44:22 CET 2009


On Mar 25, 1:07 am, Kay Schluehr <kay.schlu... at gmx.net> wrote:
> On 25 Mrz., 05:56, Carl Banks <pavlovevide... at gmail.com> wrote:
>
>
>
>
>
> > On Mar 24, 8:32 pm, Istvan Albert <istvan.alb... at gmail.com> wrote:
>
> > > On Mar 24, 9:35 pm, Maxim Khitrov <mkhit... at gmail.com> wrote:
>
> > > > Works perfectly fine with relative imports.
>
> > > This only demonstrates that you are not aware of what the problem
> > > actually is.
>
> > > Try using relative imports so that it works when you import the module
> > > itself. Now run the module as a program. The same module that worked
> > > fine when you imported it will raise the exception:
>
> > PEP 366 addresses this issue.
>
> > Not the best solution, one that still involves boilerplate, but it is
> > much less of a hack than your version, and at least it has the
> > blessing of the language designers so it won't unceremoniously break
> > at some point.
>
> A workaround that is hardly acceptable when we are working with /
> debugging 3rd party packages. Python was simpler without relative
> imports and occasional ambiguity resolutions by means of absolute
> imports. Unfortunately Brett Cannons reconstruction of import
> semantics comes a little late for Python 3 and I suppose we have to
> live with the current mess

Out of curiosity, is there anything--aside from explicit relative
imports--worked before but doesn't now?

The issue Istvan is talking about exists even with the implicit
imports.


Carl Banks



More information about the Python-list mailing list