O'Reilly logo

Python: Essential Reference, Third Edition by David Beazley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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. Therefore, 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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required