Skip to content

Latest commit

 

History

History
58 lines (43 loc) · 1.3 KB

README.md

File metadata and controls

58 lines (43 loc) · 1.3 KB

Python Import Traps

Sample codes to introduce the basic use of import in Python, and to demo some common errors

Blog (Chinese)

module_package_basics

Sample code to demo basic Python module and package relationships.

$ python3 -m module_package_basics.sample_package.sample_module_import

>>>
Hello!
import_errors

Sample code to demo common errors arrising from imcorrect import concepts, including circular import and relative import above top-level package. Also prints out messages to trace when the module or function has done loading.

$ cd import_errors
$ python3 -m sample_package.B

>>>
B started importing
A started importing
B started importing
B finished importing
B finished defining B_say_hello
B finished defining B_greet_back
A finished importing
A finished defining A_say_hello
A finished defining A_greet_back
B finished importing
B finished defining B_say_hello
B finished defining B_greet_back
B says hello!
A says hello back!
demo

Sample code to simulate a real-world project and when relative/absolute imports need to be attended to.

$ python3 -m demo.src.app

>>>
Hello!😋
$ python3 -m demo.test.test_app

>>>
Test Passes