Skip to content

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

Notifications You must be signed in to change notification settings

eds53323/python-import-traps

 
 

Repository files navigation

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

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%