Importing * From a Package

Discussion in 'Python' started by Patrick Doyle, Aug 6, 2007.

  1. 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
     
    Patrick Doyle, Aug 6, 2007
    #1
    1. Advertising

  2. Patrick Doyle

    Guest

    On Aug 6, 9:06 am, "Patrick Doyle" <> 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
     
    , Aug 6, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mhk
    Replies:
    1
    Views:
    617
    Chris Smith
    Nov 28, 2003
  2. Alex
    Replies:
    0
    Views:
    513
  3. Javabean

    importing for package

    Javabean, Mar 1, 2006, in forum: Java
    Replies:
    4
    Views:
    527
  4. Dave
    Replies:
    2
    Views:
    473
  5. plb
    Replies:
    2
    Views:
    357
Loading...

Share This Page