[Tutor] question about import statement

Steven D'Aprano steve at pearwood.info
Fri Aug 27 08:42:28 CEST 2010


On Fri, 27 Aug 2010 02:18:10 pm Greg Bair wrote:
> > yeah, "from package import *" doesn't actually import every name
> > from a module. For example, by default, names starting with an
> > underscore are not imported. Alternatively, if you have a variable
> > named __all__ in your module, and it's a list of names, only those
> > names in the list actually get imported when you do a "from x
> > import *"
> >
> > Hugo
>
> Why would the person who wrote this package choose to do it this way,
> though?  If it was something that people would use and not just an
> internal name, why hide it this way?

I can't speak for the tkinter package, but in my own packages I like to 
distinguish between three broad categories of functions (and classes):

* public functions that are part of the main functionality of the 
package;

* public functions that are associated with the package, but not 
directly part of the package functionality (e.g. helper functions, 
support functions, unittests, experimental code that is provided but 
not supported, utilities, decorators, etc.);

* private functions that I reserve the right to change or remove without 
notice.

Only the first goes into __all__. Only the third start with an 
underscore.



-- 
Steven D'Aprano


More information about the Tutor mailing list