Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e4aad5a

Browse files
committed
#18034: update FAQ to suggest importlib.import_module instead of __import__. Patch by Wouter van Heyst.
1 parent 69fb6a4 commit e4aad5a

2 files changed

Lines changed: 4 additions & 12 deletions

File tree

Doc/faq/programming.rst

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,19 +1786,10 @@ These solutions are not mutually exclusive.
17861786
__import__('x.y.z') returns <module 'x'>; how do I get z?
17871787
---------------------------------------------------------
17881788

1789-
Try::
1790-
1791-
__import__('x.y.z').y.z
1792-
1793-
For more realistic situations, you may have to do something like ::
1794-
1795-
m = __import__(s)
1796-
for i in s.split(".")[1:]:
1797-
m = getattr(m, i)
1798-
1799-
See :mod:`importlib` for a convenience function called
1800-
:func:`~importlib.import_module`.
1789+
Consider using the convenience function :func:`~importlib.import_module` from
1790+
:mod:`importlib` instead::
18011791

1792+
z = importlib.import_module('x.y.z')
18021793

18031794

18041795
When I edit an imported module and reimport it, the changes don't show up. Why does this happen?

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ Bernhard Herzog
549549
Magnus L. Hetland
550550
Raymond Hettinger
551551
Kevan Heydon
552+
Wouter van Heyst
552553
Kelsey Hightower
553554
Jason Hildebrand
554555
Richie Hindle

0 commit comments

Comments
 (0)