Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Question about import

Reply
Thread Tools

Question about import

 
 
Kevin MacKenzie
Guest
Posts: n/a
 
      08-05-2003
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
 
Reply With Quote
 
 
 
 
Tim Rowe
Guest
Posts: n/a
 
      08-05-2003
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


 
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
to use import java.lang.* or import java.lang.Math or none at all? JPractitioner Java 13 02-24-2006 08:48 PM
XML Schema question - does "import" import elements? Vitali Gontsharuk XML 2 08-25-2005 07:33 PM
IMPORT STATIC; Why is "import static" file scope? Why not class scope? Paul Opal Java 12 10-10-2004 11:01 PM
GTK import doesn't import first time Dennis Python 2 08-18-2003 10:00 PM
import/from import question Artur M. Piwko Python 1 07-02-2003 07:04 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57