Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit81d07af

Browse files
committed
Add information about modules find path in Python.
1 parentfbc81f1 commit81d07af

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

‎src/modules/test_modules.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@
1414
A module is a file containing Python definitions and statements. The file name is the module name
1515
with the suffix .py appended. Within a module, the module’s name (as a string) is available as the
1616
value of the global variable __name__.
17+
18+
When the interpreter executes the import statement, it searches for module in a list of
19+
directories assembled from the following sources:
20+
21+
- The directory from which the input script was run or the current directory if the interpreter is
22+
being run interactively
23+
- The list of directories contained in the PYTHONPATH environment variable, if it is set. (The
24+
format for PYTHONPATH is OS-dependent but should mimic the PATH environment variable.)
25+
- An installation-dependent list of directories configured at the time Python is installed
26+
27+
The resulting search path is accessible in the Python variable sys.path, which is obtained from a
28+
module named sys:
29+
30+
>>> import sys
31+
>>> sys.path
32+
33+
@see: https://realpython.com/python-modules-packages/
1734
"""
1835

1936
# This does not enter the names of the functions defined in fibonacci_module directly in the

‎src/modules/test_packages.py‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,24 @@
1313
valid modules that occur later on the module search path. In the simplest case, __init__.py can
1414
just be an empty file, but it can also execute initialization code for the package or set the
1515
__all__ variable, described later.
16-
"""
1716
18-
# The __init__.py files are required to make Python treat the directories as containing packages;
19-
# this is done to prevent directories with a common name, such as string, from unintentionally
20-
# hiding valid modules that occur later on the module search path. In the simplest case,
21-
# __init__.py can just be an empty file, but it can also execute initialization code for the
22-
# package or set the __all__ variable, described later.
17+
When the interpreter executes the import statement, it searches for module in a list of
18+
directories assembled from the following sources:
19+
20+
- The directory from which the input script was run or the current directory if the interpreter is
21+
being run interactively
22+
- The list of directories contained in the PYTHONPATH environment variable, if it is set. (The
23+
format for PYTHONPATH is OS-dependent but should mimic the PATH environment variable.)
24+
- An installation-dependent list of directories configured at the time Python is installed
25+
26+
The resulting search path is accessible in the Python variable sys.path, which is obtained from a
27+
module named sys:
28+
29+
>>> import sys
30+
>>> sys.path
31+
32+
@see: https://realpython.com/python-modules-packages/
33+
"""
2334

2435
# Users of the package can import individual modules from the package, for example.
2536
importsound_package.effects.echo

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp