[Python] import, from, as, cheatsheet

A module is a Python file that (generally) has only definitions of variables, functions, and classes.

Example, we have a lib called module.py

# module.py
def fun1(n):
return n+1

There are four way to import module.py

1- import

import module
module.fun1(1000) #1001

2- from

from module import fun1
fun1(1000) #1001

3- import *

from module import *
fun1(1000) #1001

4- import as

import module as lib
lib.fun1(1000) #1001

Reference

https://docs.python.org/2/tutorial/modules.html

https://en.wikibooks.org/wiki/A_Beginner%27s_Python_Tutorial/Importing_Modules