[Python-Dev] Imports with underscores

Ethan Furman ethan at stoneleaf.us
Mon Jan 9 11:32:30 EST 2017


On 01/09/2017 03:42 AM, Steve Holden wrote:

> 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?

Aside from what Barry said it also offers the (very) minor advantage of showing up as an implementation detail when someone does a dir() of the module.

Personally, I tend to use the technique for new code, but I wouldn't change old code for it (and new code in an old module should follow the old module's practices, etc.) .

--
~Ethan~


More information about the Python-Dev mailing list