Question about import

Discussion in 'Python' started by Kevin MacKenzie, Aug 5, 2003.

  1. 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?

    >>> from Module import *



    and

    >>> import Module



    Thanks.

    kjm
     
    Kevin MacKenzie, Aug 5, 2003
    #1
    1. Advertising

  2. Kevin MacKenzie

    Tim Rowe Guest

    On 5 Aug 2003 09:28:54 -0700, (Kevin MacKenzie)
    wrote:

    >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?
    >
    >>>> from Module import *

    >
    >
    >and
    >
    >>>> import Module


    Yes. As I said to someone else hereabouts not all /that/ long ago
    (!),
    >>>> import Module

    is the computing equivalent to getting your toolkit out of the
    cupboard and putting it on your workbench.

    >>>> from Module import *

    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()",
    >>>> import Module

    means that you can call Module.foo()

    >>>> from Module import *

    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
    >>>> import Module
     
    Tim Rowe, Aug 5, 2003
    #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. Paul Opal
    Replies:
    12
    Views:
    1,002
    Paul Opal
    Oct 11, 2004
  2. JPractitioner
    Replies:
    13
    Views:
    20,235
    Roedy Green
    Feb 24, 2006
  3. Vitali Gontsharuk
    Replies:
    2
    Views:
    605
    Vitali Gontsharuk
    Aug 25, 2005
  4. Artur M. Piwko

    import/from import question

    Artur M. Piwko, Jun 29, 2003, in forum: Python
    Replies:
    1
    Views:
    896
    Peter Hansen
    Jul 2, 2003
  5. Dennis
    Replies:
    2
    Views:
    532
    Dennis
    Aug 18, 2003
Loading...

Share This Page