[Python-checkins] peps: Improved example to just focus on sys.path manipulation.
eric.smith
python-checkins at python.org
Thu May 24 23:46:21 CEST 2012
http://hg.python.org/peps/rev/4032557ae02c
changeset: 4430:4032557ae02c
user: Eric V. Smith <eric at trueblade.com>
date: Thu May 24 17:46:07 2012 -0400
summary:
Improved example to just focus on sys.path manipulation.
files:
pep-0420.txt | 22 ++++++++++++++--------
1 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/pep-0420.txt b/pep-0420.txt
--- a/pep-0420.txt
+++ b/pep-0420.txt
@@ -372,9 +372,11 @@
child
three.py
-We add the first two parent paths to ``sys.path``. The third
-``parent`` portion is added dynamically to ``parent.__path__``, and
-the third portion is then found when it is imported::
+We add ``project1`` and ``project2`` to ``sys.path``, then import
+``parent.child.one`` and ``parent.child.two``. Then we add the
+``project3`` to ``sys.path`` and when ``parent.child.three`` is
+imported, ``project3/parent`` is automatically added to
+``parent.__path__``.
# add the first two parent paths to sys.path
>>> import sys
@@ -400,17 +402,21 @@
File "<frozen importlib._bootstrap>", line 1250, in _find_and_load_unlocked
ImportError: No module named 'parent.child.three'
- # now add the third parent portion to parent.__path__:
- >>> parent.__path__.append('Lib/test/namespace_pkgs/project3/parent')
- >>> parent.__path__
- _NamespacePath(['Lib/test/namespace_pkgs/project1/parent', 'Lib/test/namespace_pkgs/project2/parent', 'Lib/test/namespace_pkgs/project3/parent'])
+ # now add project3 to sys.path:
+ >>> sys.path.append('Lib/test/namespace_pkgs/project3')
# and now parent.child.three can be imported:
>>> import parent.child.three
- # and project3/parent/child has dynamically been added to parent.child.__path__
+ # project3/parent has been added to parent.__path__:
+ >>> parent.__path__
+ _NamespacePath(['Lib/test/namespace_pkgs/project1/parent', 'Lib/test/namespace_pkgs/project2/parent', 'Lib/test/namespace_pkgs/project3/parent'])
+
+ # and project3/parent/child has been added to parent.child.__path__
>>> parent.child.__path__
_NamespacePath(['Lib/test/namespace_pkgs/project1/parent/child', 'Lib/test/namespace_pkgs/project2/parent/child', 'Lib/test/namespace_pkgs/project3/parent/child'])
+ >>>
+
Discussion
--
Repository URL: http://hg.python.org/peps
More information about the Python-checkins
mailing list