Newbie on importing

Christopher Koppler klapotec at nusurf.at
Fri Jun 20 19:58:26 CEST 2003


Michael J Whitmore wrote:

> Just read the Python tutorial looking for the answer to this question

>  What is the difference between (from sys import *) and (import sys).
> I am aware that the last imported module's functions overwrite any
> identically named functions of previous modules.
> 
"from <module> import *" does that, while "import <module>" lets you use
the imported module's names qualified, e.g. you'll have to type "sys.maxint" instead
of just "maxint" to access maxint from module sys.
So while both expose all the names in the module for use in your program,
with the qualified import you don't have to worry about conflicting
namespaces (with names already used being overwritten) - if you'd define
a function maxint in your code, with unqualified "from sys
import *" you'd not be able to use the maxint from module sys.
However you'll also have to type a bit more ;-)


hope that clarifies it a bit,
Christopher





More information about the Python-list mailing list