Pages

Python: Modul Import

Let's prepare a new file and save as "modul.py" to "C:\Python directory".

    name = 'Flow Chart'
    color = 'White'
    list = ['python', 'html5']

Open python shell.

if we want to import our modul:

>>>import modul     #without extension ".py"
>>>modul.variable

For example:

>>>modul.name
>>>'Flow Chart'

If we dont want to use modul name over and over again:

>>>from modul import name
>>>name
>>>'Flow Chart'

If we want to import all the variable at the same time:

>>>from modul import *

We sometimes want to import variable with another name, if we already use this variable name.

>>>from import name as new_name
>>>new_name
>>>'Flow Chart'