Question about import

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kevin MacKenzie

    Question about import

    I'm a complete newbie to using Python. I have a small question about
    importing modules.

    Is there any difference between the two following statements, and what
    (if any) are they?
    [color=blue][color=green][color=darkred]
    >>> from Module import *[/color][/color][/color]


    and
    [color=blue][color=green][color=darkred]
    >>> import Module[/color][/color][/color]


    Thanks.

    kjm
  • Tim Rowe

    #2
    Re: Question about import

    On 5 Aug 2003 09:28:54 -0700, kjmacken@yorku. ca (Kevin MacKenzie)
    wrote:
    [color=blue]
    >I'm a complete newbie to using Python. I have a small question about
    >importing modules.
    >
    >Is there any difference between the two following statements, and what
    >(if any) are they?
    >[color=green][color=darkred]
    >>>> from Module import *[/color][/color]
    >
    >
    >and
    >[color=green][color=darkred]
    >>>> import Module[/color][/color][/color]

    Yes. As I said to someone else hereabouts not all /that/ long ago
    (!),[color=blue][color=green][color=darkred]
    >>>> import Module[/color][/color][/color]
    is the computing equivalent to getting your toolkit out of the
    cupboard and putting it on your workbench.
    [color=blue][color=green][color=darkred]
    >>>> from Module import *[/color][/color][/color]
    is the computing equivalent of getting your toolkit out of the
    cupboard, tipping the contents onto the workbench, and putting the box
    back into the cupboard.

    If "Module" contains "foo()",[color=blue][color=green][color=darkred]
    >>>> import Module[/color][/color][/color]
    means that you can call Module.foo()
    [color=blue][color=green][color=darkred]
    >>>> from Module import *[/color][/color][/color]
    means that you can use foo(). But if your code or any other module
    contains something called "foo()" then you get a name clash. That can
    be nasty, because you can get everything working fine, and somebody
    using a library that's supposed to be compatable with the one you've
    tested finds it doesn't work.

    For all but the very simplest of code, use[color=blue][color=green][color=darkred]
    >>>> import Module[/color][/color][/color]

    Comment

    Working...