[Tutor] Why do I not get an error when I mistakenly type "humdrum.sigh_strenght" instead of the correct "humdrum.sigh_strength"?

Alan Gauld alan.gauld at btinternet.com
Sat Jan 23 20:06:19 EST 2016


On 23/01/16 19:17, boB Stepp wrote:

> "_single_leading_underscore : weak "internal use" indicator. E.g. from
> M import * does not import objects whose name starts with an
> underscore."
> 
> My current understanding is to avoid "from M import *", but it is good
> to know that this style of import will not capture names of the form
> "_name".

There is another way to control what gets exported from modules.
You can define a variable in the module called __all__ which
contains a list of names that you are happy to export.

Then if someone does from m import * only the names in
m.__all__ will actually be made  visible.

But that doesn't do anything to stop those names colliding
with similar names from another module, it just provides some
token privacy for names you specifically don't want exported.

hth
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list