diff --git a/Day 10 homework - Sloetjes .md b/Day 10 homework - Sloetjes .md index 744edd3..1865672 100644 --- a/Day 10 homework - Sloetjes .md +++ b/Day 10 homework - Sloetjes .md @@ -1,8 +1,9 @@ -1. Run the module-inspector script, and fix any problems that prevent it from running. +**1. Run the module-inspector script, and fix any problems that prevent it from running. +** +**2. Look at the output. Notice that some of the module names seem similar, and are cached via two different loader methods.** -2. Look at the output. Notice that some of the module names seem similar, and are cached via two different loader methods. +**3. Based on what you see from the module-inspector script, modify your answer from question 10 from the day 9 homework, so the similar module names aren't counted multiple times.** -3. Based on what you see from the module-inspector script, modify your answer from question 10 from the day 9 homework, so the similar module names aren't counted multiple times. ``` import sys import os @@ -75,6 +76,7 @@ def print_module_stats(): if __name__ == '__main__': print_module_stats() ``` + By using a set called `module_files` to keep track of the filenames of the modules that we have counted so far. Before counting a module, we check if its filename has been counted already. If it has, we skip the module and move on to the next one. This ensures that similar module names are counted only once. 4. Inspect the `__loader__` attribute of each entry in the `sys.modules` dict. Can you find an attribute of `__loader__` which reliably tells you if the loader is source, builtin, or extension?