Update page 'Day 9 homework - Sloetjes'

xuanyi.wang
2023-04-19 04:56:29 +02:00
parent 3ae82b6cb6
commit 220397b889
+4
@@ -73,3 +73,7 @@ print(login)
* According to the Python language reference documentation on Importing Modules (section 5.6), the `__import__()` function is a low-level interface for dynamically importing modules at runtime. The documentation states that: * According to the Python language reference documentation on Importing Modules (section 5.6), the `__import__()` function is a low-level interface for dynamically importing modules at runtime. The documentation states that:
> When the name variable is of the form package.module, normally, the top-level package (the name up till the first dot) is returned, not the module named by name. However, when a non-empty fromlist argument is given, the module named by name is returned. > When the name variable is of the form package.module, normally, the top-level package (the name up till the first dot) is returned, not the module named by name. However, when a non-empty fromlist argument is given, the module named by name is returned.
* In the code above, the name of the module is '"os"', and the fromlist argument is not given, so the top-level package '"os"' is returned, which is equivalent to importing os with a regular import statement.
Therefore, the expression '__import__('os').getlogin()' is equivalent to 'os.getlogin()', but it dynamically imports the 'os' module at runtime instead of using a regular import statement.