Sep. 27, 2012

How to import modules in Python


Python modules makes the programming a lot easier. 

It's basically a file that consist of already written code. 

When Python imports a module, it first checks the module registry (sys.modules)
to see if the module is already imported. 

If that’s the case, Python uses the existing module object as is. 

Importing Modules

There are different ways to import a module

import sys    		
# access module, after this you can use to refer to
# things defined in module sys.

from sys import stdout  
# access module without qualiying name. 
# This reads >> from the module "sys" import "stdout", so that
# we would be able to refer "stdout" in our program.

from sys import *       
# access all functions/classes in the sys module. 

Recommended Python Training – DataCamp

For Python training, our top recommendation is DataCamp.

Datacamp provides online interactive courses that combine interactive coding challenges with videos from top instructors in the field.

Datacamp has beginner to advanced Python training that programmers of all levels benefit from.


Read more about:
Disclosure of Material Connection: Some of the links in the post above are “affiliate links.” This means if you click on the link and purchase the item, I will receive an affiliate commission. Regardless, only recommend products or services that we try personally and believe will add value to our readers.