[Python-ideas] Allow multiple imports from a package while preserving its namespace

Julian DeMille julian.demille at demilletech.net
Thu Apr 26 09:53:58 EDT 2018


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.

On Thu, Apr 26, 2018 at 9:51 AM Nick Coghlan <ncoghlan at gmail.com> wrote:

> On 26 April 2018 at 23:37, Paul Moore <p.f.moore at gmail.com> wrote:
> > On 26 April 2018 at 14:29, Julian DeMille via Python-ideas
> > <python-ideas at python.org> wrote:
> >> I personally would like a feature where instead of doing `from ...
> import
> >> ...` (which imports the specified items into the current namespace), one
> >> could use something along the lines of `import <lib>.{ <mod1>, <mod2>,
> ...
> >> }` such that the imported modules/attributes could be accessed as
> >> `<lib>.<mod1>`, etc.
> >
> > What are the benefits of this over a simple "import <lib>"?
>
> Forcing submodule imports would be the main thing, as at the moment,
> you have to choose between repeating the base name multiple times
> (once per submodule) or losing the hierarchical namespace.
>
> So where:
>
>     from pkg import mod1, mod2, mod3
>
> bind "mod1", "mod2", and "mod3" in the current namespace, you might
> instead write:
>
>     from pkg import .mod1, .mod2, .mod3
>
> to only bind "pkg" locally, but still make sure "pkg.mod1", "pkg.mod2"
> and "pkg.mod3" all resolve at import time.
>
> Cheers,
> Nick.
>
> --
> Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
>
-- 
Thanks,
Julian DeMille

CEO, demilleTech, LLC

This email and any files transmitted with it are confidential and intended
solely for the use of the individual or entity to whom they are addressed.
If you have received this email in error please notify the system manager.
This message contains confidential information and is intended only for the
individual named. If you are not the named addressee you should not
disseminate, distribute or copy this e-mail. Please notify the sender
immediately by e-mail if you have received this e-mail by mistake and
delete this e-mail from your system. If you are not the intended recipient
you are notified that disclosing, copying, distributing or taking any
action in reliance on the contents of this information is strictly
prohibited.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180426/f2be906b/attachment.html>


More information about the Python-ideas mailing list