0
0
Pythonprogramming~10 mins

Module search path in Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the sys module.

Python
import [1]
Drag options to blanks, or click blank then click option'
Amath
Bos
Csys
Drandom
Attempts:
3 left
💡 Hint
Common Mistakes
Importing a different module like os or math instead of sys.
2fill in blank
medium

Complete the code to print the list of directories Python searches for modules.

Python
import sys
print(sys.[1])
Drag options to blanks, or click blank then click option'
Amodules
Bsearch
Cpaths
Dpath
Attempts:
3 left
💡 Hint
Common Mistakes
Using sys.modules which is a dictionary of loaded modules, not paths.
3fill in blank
hard

Fix the error in the code to add a new directory to the module search path.

Python
import sys
sys.path.[1]('/my/custom/path')
Drag options to blanks, or click blank then click option'
Aappend
Badd
Cinsert
Dextend
Attempts:
3 left
💡 Hint
Common Mistakes
Using add which is not a list method.
Using extend which expects an iterable, not a single string.
4fill in blank
hard

Fill both blanks to insert a directory at the start of the module search path.

Python
import sys
sys.path.[1](0, [2])
Drag options to blanks, or click blank then click option'
Ainsert
B'/new/path'
C'/custom/dir'
Dappend
Attempts:
3 left
💡 Hint
Common Mistakes
Using append instead of insert to add at the start.
Passing the directory as the first argument instead of the second.
5fill in blank
hard

Fill all three blanks to create a new list of directories from sys.path that contain 'site-packages'.

Python
import sys
site_dirs = [p[1] for p in sys.[2] if 'site-packages' [3] p]
Drag options to blanks, or click blank then click option'
A for p in sys.path
Bpath
Cin
Dif
Attempts:
3 left
💡 Hint
Common Mistakes
Using if instead of in for substring check.
Incorrectly writing the list comprehension syntax.