Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Importing * From a Package

Reply
Thread Tools

Importing * From a Package

 
 
Patrick Doyle
Guest
Posts: n/a
 
      08-06-2007
Reading through the Python tutorial, I got to section 6.4.1,
"Importing * From a Package", which states:

"If __all__ is not defined, the statement from Sound.Effects import *
does not import all submodules from the package Sound.Effects into the
current namespace; ..."

It then goes on to state:

"[It] imports whatever names are defined in the package [including]
any submodules of the package that were explicitly loaded by previous
import statements."

I am curious to learn the rationale for this behavior, since it just
caught me by surprise (hence the reason I was pouring over the
tutorial document in such detail )

Thus far, everything in Python has seemed very intuitive to me,
however the behavior of "from package import *" baffles me.

So I figured I'd ask -- why does Python behave this way.

(And now, I'm going to do some code cleanup )

--wpd
 
Reply With Quote
 
 
 
 
kyosohma@gmail.com
Guest
Posts: n/a
 
      08-06-2007
On Aug 6, 9:06 am, "Patrick Doyle" <wpds...@gmail.com> wrote:
> Reading through the Python tutorial, I got to section 6.4.1,
> "Importing * From a Package", which states:
>
> "If __all__ is not defined, the statement from Sound.Effects import *
> does not import all submodules from the package Sound.Effects into the
> current namespace; ..."
>
> It then goes on to state:
>
> "[It] imports whatever names are defined in the package [including]
> any submodules of the package that were explicitly loaded by previous
> import statements."
>
> I am curious to learn the rationale for this behavior, since it just
> caught me by surprise (hence the reason I was pouring over the
> tutorial document in such detail )
>
> Thus far, everything in Python has seemed very intuitive to me,
> however the behavior of "from package import *" baffles me.
>
> So I figured I'd ask -- why does Python behave this way.
>
> (And now, I'm going to do some code cleanup )
>
> --wpd


The only module I know of that most people tell you to do a "from x
import *" is Tkinter. I think that's pretty dumb myself. If you don't
want to type some module's name out, then do something like "import
Tkinter as tk".

Mike

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
importing for package Javabean Java 4 03-02-2006 12:05 AM
Importing Package through Jar in JCreator Parameter Names problem Alex Java 0 02-20-2006 05:19 AM
How to keep a module with the same name as a module it is importing from importing itself? plb Python 2 02-08-2005 03:14 PM
Importing a package and looping through modules in the package Dave Python 2 02-10-2004 08:14 PM
importing classs without package in JSP ? mhk Java 1 11-28-2003 11:46 PM



Advertisments