Python

Importing Python Modules

The import and from-import statements are somewhat confusion for beginners to Python.
Here we will discuss some common issues related to import and from-import.
Python have 3 different ways to import modules.
1. import statement
2. from statement
3. builtin __import__ function

import X imports the module X, and creates a reference to that module in the current namespace.So you have to use X.name to refer to things defined in module X.
from X import * imports the module X, and creates references in the current namespace to all public objects defined by that module (that is, everything that doesn’t have a name starting with “_”) hence you can simply use a plain name to refer to things defined in module X. Since X itself is not defined, so X.name doesn’t work.
from X import a, b, c imports the module X, and creates references in the current namespace to the given objects i.e a,b,c.

Cumulus Tag Cloud

Kiran Says

SEO Architect,SEO Specialist reflect my values.

By enduring black hat methods the SEO industry is setting itself up for washout and sleepwalking into oblivion.

Jobs in India