[Python-ideas] Importing public symbols and simultainiously privatizing them, is too noisy

Chris Barker chris.barker at noaa.gov
Fri Mar 18 17:29:37 EDT 2016


On Wed, Mar 16, 2016 at 6:52 PM, Rick Johnson <rantingrickjohnson at gmail.com>
wrote:

> > Besides, why is "import x as _x" so special to require special syntax?
>

It's not :-) I know I do, for instance,

from matplotlib  import pylot as plt

But have NEVER done the leading underscore thing...


>  from module import Foo as _Foo, bar as _bar, BAZ as _BAZ, spam as _spam,
> eggs as _eggs
>

if you are mirroring an entire namespace, or a god fraction of one then use
a module name!

import module as _mod

then use _mod.Foo, etc.....

Now, that may seem like a contrived example, but i've
> witnessed much longer "run-on import lines" than that.
>

I have too, but I think it's  bad style -- if you are importing a LOT of
names from one module, just import the darn module -- giving it a shorter
name if you like. This has become a really standard practice, like:

import numpy as np

for instance.

The intended purpose is to: "automate the privatization of
> public symbols during the import process".
>

I'm really confused about the use case for "privatization of public
symbols" at all, but again, if you need a lot of them, use the module name
to prefix them. Heck give it a one character name, and then it's hardly
more typing than the underscore...

-CHB


-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160318/44e88f93/attachment-0001.html>


More information about the Python-ideas mailing list