Thursday, April 4, 2013

What's the difference between "import" and "from...import *" in Python?

"import <ModuleName>" loads a Python module into its own namespace and restricts direct access to the members of the module. The references can be accessed by prefixing the module name followed by a dot.

import sys
sys.exit()

On the contrary, "from <ModuleName> import *" loads a module into the current namespace and allows to access those references without a prefix.

from sys import *
exit()

No comments :