Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The short answer is that <code>os.remove(module_name)</code> will remove a file from the filesystem. <code>del sys.modules["module_name"]</code> will remove a module from the cache of previously loaded modules that the current Python interpreter is maintaining.</p> <p>In Python, when you import a module, the interpreter checks to see if there is a <code>.pyc</code> file of the same name as the <code>.py</code> file you are trying to import. If there is, and if the <code>.py</code> file has not changed since the <code>.pyc</code> file has been imported, then Python will load the <code>.pyc</code> file (which is significantly faster). </p> <p>If the <code>.pyc</code> file does not exist, or the <code>.py</code> file has been changed since the <code>.pyc</code> file was created, then the <code>.py</code> file is loaded and a new <code>.pyc</code> file is created. (It is worth noting that simply running a Python file, say <code>test.py</code> will <em>not</em> cause a <code>test.pyc</code> to be created. Only <code>import</code>ing modules causes this to happen.)</p> <p><code>sys.modules</code> is another matter entirely. In order to speed up code which imports the same module twice, Python maintains a list of the modules that have been imported during the current interpreter session. If the module being imported is in <code>sys.modules</code>, then the cached version will be read (neither <code>.py</code> nor <code>.pyc</code> files will be checked for on the disk). Python provides a builtin function <a href="http://docs.python.org/library/functions.html" rel="nofollow noreferrer"><code>reload()</code></a> which allows you to bypass the module cache and force a reload from disk.</p> <p>To get more information on Python's module system, see the docs on <a href="http://docs.python.org/tutorial/modules.html#compiled-python-files" rel="nofollow noreferrer">modules</a>.</p>
    singulars
    1. This table or related slice is empty.
    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