I just ran into a similar problem, how to relatively import without binding
the submodule.

Let's say you have this :
myapp/
    urls.py
    views/
        base.py

When you're in urls.py and you want to relatively access Functions from
base.py, you must use the from syntax.

from .views import base
base.func()

But what if I just want "views" in my namespace?

from . import views
from .views import base
views.base.func()
base.func()

import myapp.views.base
myapp.views.base.func()

from . import views
import myapp.views.base
views.base.func()
myapp.views.base.func()

Le jeu. 26 avr. 2018 à 17:24, Chris Angelico <ros...@gmail.com> a écrit :

> On Thu, Apr 26, 2018 at 11:53 PM, Julian DeMille via Python-ideas
> <python-ideas@python.org> wrote:
> > That's the kind of thing I'm looking for. I've dealt with some library
> > authors who were highly against importing the root allowing me to access
> > submodules with hierarchy.
>
> With a package, having automatic imports forces those submodules to be
> loaded eagerly (as soon as you import the package, you load up those
> modules). Lazily-loaded submodules can improve performance if you
> don't always need them.
>
> +0 for an easier way to import multiple submodules at once. It's not
> something I've personally had a need for, but it's a sane and logical
> thing to do.
>
> ChrisA
> _______________________________________________
> Python-ideas mailing list
> Python-ideas@python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to