[Python-Dev] relative import circular problem

Greg Ewing greg.ewing at canterbury.ac.nz
Wed Apr 3 01:12:34 CEST 2013

Kristján Valur Jónsson wrote:
> However, relative imports can _only_ be performed using the "from X import Y syntax"

This seems like a legitimate complaint on its own, regardless
of the circular import issue. The principle of least surprise
suggests that relative imports should be possible using either

I'm guessing the reason that 'import' doesn't support relative
imports is that it's not clear what name to bind the imported
module to.

There are a couple of ways that this could be resolved. One
would be to use the name resulting from stripping off the
leading dots, so that

    import .foo

would bind the module to the name 'foo'. Another would be
to always require an 'as' clause in this case, so that you
would have to write'

    import .foo as foo


More information about the Python-Dev mailing list