Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>So, far I have been exiting and reentering the Interpreter because re importing the file again is not working for me.</p> </blockquote> <p>Yes, just saying <code>import</code> again gives you the existing copy of the module from <code>sys.modules</code>.</p> <p>You can say <code>reload(module)</code> to update <code>sys.modules</code> and get a new copy of that single module, but if any other modules have a reference to the original module <em>or any object from the original module</em>, they will keep their old references and Very Confusing Things will happen.</p> <p>So if you've got a module <code>a</code>, which depends on module <code>b</code>, and <code>b</code> changes, you have to ‘reload b’ followed by ‘reload a’. If you've got two modules which depend on each other, which is extremely common when those modules are part of the same package, you can't reload them both: if you reload <code>p.a</code> it'll get a reference to the old <code>p.b</code>, and vice versa. The only way to do it is to unload them both at once by deleting their items from <code>sys.modules</code>, before importing them again. This is icky and has some practical pitfalls to do with modules entries being None as a failed-relative-import marker.</p> <p>And if you've got a module which passes references to its objects to system modules — for example it registers a codec, or adds a warnings handler — you're stuck; you can't reload the system module without confusing the rest of the Python environment.</p> <p>In summary: for all but the simplest case of one self-contained module being loaded by one standalone script, <code>reload()</code> is very tricky to get right; if, as you imply, you are using a ‘package’, you will probably be better off continuing to cycle the interpreter.</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. 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