Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Imports

1. import module next to script

import SimpleModule
from SimpleModule import simplefunction

2. import module from package

import Package
from Package import Module
from Package.Module import moduleMethod

3. import module from subpackage

from Package import SubPackage
from Package.SubPackage import SubModule
from Package.SubPackage.SubModule import subModuleMethod

4. import subpackage with intrapackage reference

# a) absolute import from Package (prefered!)
from Package.SubPackage import SubModule

# b) relative import from current submodule
from ..SubPackage import SubModule

Run main.py

initialized:  SimpleModule
initialized:  Package
initialized:  Package.Module
initialized:  Package.SubPackage
initialized:  Package.SubPackage.SubModule
initialized:  Package.AnotherSubPackage
initialized:  Package.AnotherSubPackage.AnotherSubModule

1. module next to script
simplefunction()
simplefunction()

2. module from package
moduleMethod()
moduleMethod()
moduleMethod()

3. module from subpackage
subModuleMethod()
subModuleMethod()
subModuleMethod()
subModuleMethod()

4. intrapackage reference in submodule
anotherSubModuleMethod()
subModuleMethod()

About

import module/package/subpackage

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages