From 500b920f1717f1d0af5069a4389e9e0d89d940bf Mon Sep 17 00:00:00 2001 From: peterhinch Date: Sat, 14 Jan 2023 16:57:24 +0000 Subject: [PATCH] Add notes on import. --- import/IMPORT.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/import/IMPORT.md b/import/IMPORT.md index 188bd54..d7f37b5 100644 --- a/import/IMPORT.md +++ b/import/IMPORT.md @@ -100,3 +100,12 @@ def reload(mod): gc.collect() __import__(mod_name) ``` +## 4.1 Indirect import + +The above code sample illustrates the method of importing a module where the +module name is stored in a variable: +```python +def run_test(module_name): + mod = __import__(module_name) + mod.test() # Run a self test +```