gh-89885: Improve import example in language reference (#91523)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
parent
efbc668183
commit
d5a69571f5
@ -490,21 +490,19 @@ submodule. Let's say you have the following directory structure::
|
|||||||
spam/
|
spam/
|
||||||
__init__.py
|
__init__.py
|
||||||
foo.py
|
foo.py
|
||||||
bar.py
|
|
||||||
|
|
||||||
and ``spam/__init__.py`` has the following lines in it::
|
and ``spam/__init__.py`` has the following line in it::
|
||||||
|
|
||||||
from .foo import Foo
|
from .foo import Foo
|
||||||
from .bar import Bar
|
|
||||||
|
|
||||||
then executing the following puts a name binding to ``foo`` and ``bar`` in the
|
then executing the following puts name bindings for ``foo`` and ``Foo`` in the
|
||||||
``spam`` module::
|
``spam`` module::
|
||||||
|
|
||||||
>>> import spam
|
>>> import spam
|
||||||
>>> spam.foo
|
>>> spam.foo
|
||||||
<module 'spam.foo' from '/tmp/imports/spam/foo.py'>
|
<module 'spam.foo' from '/tmp/imports/spam/foo.py'>
|
||||||
>>> spam.bar
|
>>> spam.Foo
|
||||||
<module 'spam.bar' from '/tmp/imports/spam/bar.py'>
|
<class 'spam.foo.Foo'>
|
||||||
|
|
||||||
Given Python's familiar name binding rules this might seem surprising, but
|
Given Python's familiar name binding rules this might seem surprising, but
|
||||||
it's actually a fundamental feature of the import system. The invariant
|
it's actually a fundamental feature of the import system. The invariant
|
||||||
|
Loading…
x
Reference in New Issue
Block a user