How does a python module search path work? Flashcards

(5 cards)

1
Q

general summary

A

In Python, module imports are guided by a set of directories called the module search path.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Module Search Path

Default Values

A

Global: Configured at Python installation time.

User-specific: User’s home directory, described in the PYTHONHOME environment variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Module Search Path

Stack-Up Mechanism

A

Command Line: Specified using the -m or -c flags.

Environment: Dictated by PYTHONPATH.

Standard Defaults: Follows a predetermined sequence.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Module Search Path

Adjusting the Search Path

A

Manual Extension: Use sys.path to add locations programmatically.

User-Centered: Touched upon in the site module, useful for local modifications.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Code Example: Customizing the Module Search Path

A
import sys

Display the current module search path
print(sys.path)

Add a temporary directory to the module search path
sys.path.append('/path/to/custom/modules')
How well did you know this?
1
Not at all
2
3
4
5
Perfectly