Entry
Re-importing modules
Jul 5th, 2000 09:59
Nathan Wallace, unknown unknown, Hans Nowak, Snippet 26, Python Snippet Support Team
"""
Packages: modules_and_packages
"""
"""
>I want to define new modules. These reside
>in subdirectories under the PythonPath. They
>seem to require an __init__.py. If I just put a
>blank one in the directory this seems to work
>fine. It seems like this file is to allow general
>definitions that are shared by the module. Is
>this correct? What would typically go in there?
Myself, I usually only use it to put a docstring for the package...
>If I am using Python and debugging a module
>I'll do an import and then run a test. I'll see that
>it's broken and fix the code in the module. Now
>how do I un-import or re-import to get the fixed
>code?
Use reload:
"""
# Let's assume we have a little module bogus.py with only a line " x = 3 "
import bogus
print bogus.x # prints 3
# Through an external editor, we change bogus.py so that it reads " x = 4 "
reload(bogus)
print bogus.x # should be 4 now