diff --git a/Day 9 homework - Sloetjes.md b/Day 9 homework - Sloetjes.md index 78b95c5..9a696e2 100644 --- a/Day 9 homework - Sloetjes.md +++ b/Day 9 homework - Sloetjes.md @@ -60,4 +60,14 @@ print(get_all_modules_size()) **6. Import the os module. What happens when you type `type(os)`?** ##### Answer: -The `type()` function returns the type of the `os` module, which is a module object. \ No newline at end of file +* The `type()` function returns the type of the `os` module, which is a module object. + +**7. Restart the Python interpreter. Can you figure out how to call `os.getlogin()` without saying `import os`?** +``` +login = __import__('os').getlogin() +print(login) +``` +8. If you can, explain why this works and quote the relevant sections of section 5 in the language reference. +##### Answer: +* 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.