[Python-Dev] Imports with underscores

Daniel Holth dholth at gmail.com
Mon Jan 9 13:42:58 EST 2017


Easily solved with the totally evil ninja mode pattern of module
initialization. It has yet to catch on.

def ninja():
    global exported
    import os
    def exported():
        # do something
ninja()
del ninja

On Mon, Jan 9, 2017 at 1:13 PM Sven R. Kunze <srkunze at mail.de> wrote:

> Interesting to see that others have the same problem.
>
> We also had this kind of "over-protective" behavior. As far as I know, our
> devs stopped doing it as it feels cumbersome.
>
>
> Another argument for this is: when using PyCharm, this IDE will suggest
> imports from those modules which aren't the original ones. So, you might
> import from a third-party module. Over time, however, people learn to pick
> the "right" module to import from.
>
> Cheers,
> Sven
>
>
> On 09.01.2017 12:42, Steve Holden wrote:
>
> One of my developers recently submitted a pull request incuding a number
> of lines like
>
> import os as _os
>
> When I asked him why he suggested a) this would improve encapsulation, and
> b) the practice was supported in the stdlib. Further investigation reveals
> that some modules (e.g. argparse, crypt, difflib, random) do use this
> technique, but it is far from universal.
>
> So I thought it would be useful to get input from current devs about the
> value of this practice, since to me it seems somewhat anti-pythonic. What
> advantages does it confer?
>
> regards
> Steve Holden
>
>
> _______________________________________________
> Python-Dev mailing listPython-Dev at python.orghttps://mail.python.org/mailman/listinfo/python-dev
>
>
> Unsubscribe: https://mail.python.org/mailman/options/python-dev/srkunze%40mail.de
>
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> https://mail.python.org/mailman/options/python-dev/dholth%40gmail.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20170109/7f37c7eb/attachment.html>


More information about the Python-Dev mailing list