471,336 Members | 956 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,336 software developers and data experts.

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

and
import Module

Thanks.

kjm
Jul 18 '05 #1
1 1554
On 5 Aug 2003 09:28:54 -0700, kj******@yorku.ca (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


Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by djw | last post: by
6 posts views Thread by Jon | last post: by
16 posts views Thread by dario | last post: by
1 post views Thread by deko | last post: by
3 posts views Thread by David Hirschfield | last post: by
5 posts views Thread by Steven W. Orr | last post: by
17 posts views Thread by Suresh Pillai | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.