3. import

3.1. Using

import ...

3.2. Importing

  • Imports module:

    import module
    
  • From module imports function:

    from module import function
    from module.submodule import function
    
  • Aliases

    import module as alias
    from module import function as alias
    
  • Relative imports:

    from . import module
    from .. import module
    
    from .module import function
    from ..module import function
    

3.2.1. Example

import sys

sys.path
sys.path.append
sys.path.insert(0, '/path/to/directory')
game
    __init__.py
    config.py
    api.py
    dragon
        __init__.py
        wawelski.py
        red.py
        black.py
        white.py
from game.config import RESOLUTION_MAX_X
from game.dragon import red
from game.dragon import white


my_dragon1 = red.RedDragon()
my_dragon2 = white.WhiteDragon()
from game.dragon import *

my_dragon1 = red.RedDragon()
my_dragon2 = white.WhiteDragon()
from game.dragon.red import RedDragon
from game.dragon.white import WhiteDragon

my_dragon1 = RedDragon()
my_dragon2 = WhiteDragon()
from game.dragon.red import RedDragon as Smok

wawelski = Smok()