How to re-import a function from a module?

Ben Finney bignose+hates-spam at benfinney.id.au
Wed Nov 5 21:16:51 EST 2008


Kurda Yon <kurdayon at yahoo.com> writes:

> Is there a way to force Python to re-import the function, i.e. to
> force it to use the new version of the function?

A Python ‘import’ is conceptually two steps: execute the module, then
bind the objects that were created to names in a namespace.

The import mechanism has a short-cut: if the module has already been
imported by this Python VM, the module isn't executed again, and the
existing objects are simply re-used with new bindings as necessary.

What you want is to specifically request the module to be re-executed
to re-create the objects again, and re-bind the existing name bindings
to the objects that result.

   >>> help(reload)

-- 
 \     “I hope that after I die, people will say of me: ‘That guy sure |
  `\                            owed me a lot of money’.” —Jack Handey |
_o__)                                                                  |
Ben Finney



More information about the Python-list mailing list