Linux/Unix > Python Essential Reference, Second Edition > 8. Modules and Packages > Module Reloading | See All Titles

< BACK | Make Note | Bookmark | CONTINUE >

155117184014003188065099048180054212144238241179195140058238111161105084124002225148015018

### Module Reloading

The built-in function `reload()` can be used to reload and execute the code contained within a module previously loaded with `import`. It accepts a module object as a single argument. For example:

    import foo
    ... some code ...
    reload(foo)          # Reloads foo

All operations involving the module after the execution of `reload()` will utilize the newly loaded code. However, `reload()` doesn’t retroactively update objects created using the old module. Thus, it’s possible for references to coexist for objects in both the old and new versions of a module. Furthermore, compiled extensions written in C or C++ cannot be reloaded using `reload()`.

As a general rule, avoid module reloading except during debugging and development.

| Last updated on 3/28/2002 Python Essential Reference, Second Edition, © 2002 New Riders Publishing

< BACK | Make Note | Bookmark | CONTINUE >

© 2002, O'Reilly & Associates, Inc.