Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can reload a module when it has already been imported by using the <a href="https://docs.python.org/2.7/library/functions.html#reload" rel="noreferrer"><code>reload</code></a> builtin function in Python 2:</p> <pre><code>import foo while True: # Do some things. if is_changed(foo): foo = reload(foo) </code></pre> <p>In Python 3, <code>reload</code> was moved to the <a href="https://docs.python.org/3.2/library/imp.html" rel="noreferrer"><code>imp</code></a> module. In 3.4, <code>imp</code> was deprecated in favor of <a href="https://docs.python.org/3.4/library/importlib.html" rel="noreferrer"><code>importlib</code></a>, and <a href="https://docs.python.org/3.4/library/importlib.html#importlib.reload" rel="noreferrer"><code>reload</code></a> was added to the latter. When targeting 3 or later, either reference the appropriate module when calling <code>reload</code> or import it.</p> <p>I think that this is what you want. Web servers like Django's development server use this so that you can see the effects of your code changes without restarting the server process itself.</p> <p>To quote from the docs:</p> <blockquote> <p>Python modules’ code is recompiled and the module-level code reexecuted, defining a new set of objects which are bound to names in the module’s dictionary. The init function of extension modules is not called a second time. As with all other objects in Python the old objects are only reclaimed after their reference counts drop to zero. The names in the module namespace are updated to point to any new or changed objects. Other references to the old objects (such as names external to the module) are not rebound to refer to the new objects and must be updated in each namespace where they occur if that is desired.</p> </blockquote> <p>As you noted in your question, you'll have to reconstruct <code>Foo</code> objects if the <code>Foo</code> class resides in the <code>foo</code> module.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload