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

Skip to content

Commit 4f422e3

Browse files
committed
Issue #17177: Update the programming FAQ to use importlib
1 parent 82b3d6a commit 4f422e3

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

Doc/faq/programming.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,12 +1738,12 @@ When I edit an imported module and reimport it, the changes don't show up. Why
17381738
For reasons of efficiency as well as consistency, Python only reads the module
17391739
file on the first time a module is imported. If it didn't, in a program
17401740
consisting of many modules where each one imports the same basic module, the
1741-
basic module would be parsed and re-parsed many times. To force rereading of a
1741+
basic module would be parsed and re-parsed many times. To force re-reading of a
17421742
changed module, do this::
17431743

1744-
import imp
1744+
import importlib
17451745
import modname
1746-
imp.reload(modname)
1746+
importlib.reload(modname)
17471747

17481748
Warning: this technique is not 100% fool-proof. In particular, modules
17491749
containing statements like ::
@@ -1755,10 +1755,10 @@ module contains class definitions, existing class instances will *not* be
17551755
updated to use the new class definition. This can result in the following
17561756
paradoxical behaviour:
17571757

1758-
>>> import imp
1758+
>>> import importlib
17591759
>>> import cls
17601760
>>> c = cls.C() # Create an instance of C
1761-
>>> imp.reload(cls)
1761+
>>> importlib.reload(cls)
17621762
<module 'cls' from 'cls.py'>
17631763
>>> isinstance(c, cls.C) # isinstance is false?!?
17641764
False

0 commit comments

Comments
 (0)