<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How can I reload a Python module on the *first* attempt?]]></title><description><![CDATA[<p dir="auto">Re: <a href="/topic/546/working-with-modules">Working with modules</a></p>
<p dir="auto">The post above gives a very helpful suggestion of how to reload modules while working on a script, but I have a question.</p>
<h2>Question</h2>
<p dir="auto">I can only get modules to reload on the <em>second</em> time I run a script.</p>
<p dir="auto">For example, here's a project setup:</p>
<pre><code class="language-console">myScript
├── __init__.py
├── myScript.py
└── helpers
    ├── __init__.py
    └── myScriptHelper.py
</code></pre>
<p dir="auto"><code>myScriptHelper.py</code> looks like this:</p>
<pre><code class="language-python">def testReload():
    print("hello, I'm reloaded")
</code></pre>
<p dir="auto">And <code>myScript.py</code> looks like this:</p>
<pre><code class="language-python">import importlib
import helpers
from helpers.myScriptHelper import *

print("hello from myScript")

importlib.reload(helpers.myScriptHelper)
testReload()
</code></pre>
<p dir="auto">So, I would expect to see "hello, I'm reloaded" in the Output Window when I run <code>myScript.py</code>. <em>However,</em> I'm finding that I only end up seeing updates to <code>myScriptHelper.py</code> on the second time I run <code>myScript.py</code> after making any changes.</p>
<h2>Example</h2>
<p dir="auto">I run <code>myScript.py</code>. In the Output, I see this:</p>
<pre><code class="language-console">hello from myScript
hello, I'm reloaded
</code></pre>
<p dir="auto">Next, I change <code>myScriptHelper.py</code> to this:</p>
<pre><code class="language-python">def testReload():
    print("hello, I'm REALLY reloaded")
</code></pre>
<p dir="auto">However, when I run <code>myScript.py</code> again, I see the same output again:</p>
<pre><code class="language-console">hello from myScript
hello, I'm reloaded
hello from myScript
hello, I'm reloaded
</code></pre>
<p dir="auto">It's only when I run <code>myScript.py</code> <em>again a second time</em> that I see the output of the updated module:</p>
<pre><code class="language-console">hello from myScript
hello, I'm reloaded
hello from myScript
hello, I'm reloaded
hello from myScript
hello, I'm REALLY reloaded
</code></pre>
<hr />
<p dir="auto">Have I missed a step, or is it expected that it should take two runs of a script for <code>importlib.reload()</code> to take effect?</p>
<p dir="auto">Thanks for any help here! I know this is a tiny question, but I'm trying to learn how to do the little things right so I can be more effective overall. :)</p>
]]></description><link>https://forum.robofont.com/topic/722/how-can-i-reload-a-python-module-on-the-first-attempt</link><generator>RSS for Node</generator><lastBuildDate>Sat, 15 Aug 2026 03:35:09 GMT</lastBuildDate><atom:link href="https://forum.robofont.com/topic/722.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 02 Nov 2019 20:09:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How can I reload a Python module on the *first* attempt? on Mon, 04 Nov 2019 09:53:36 GMT]]></title><description><![CDATA[<p dir="auto">Re: <a href="/topic/546/working-with-modules">Working with modules</a></p>
<p dir="auto">The post above gives a very helpful suggestion of how to reload modules while working on a script, but I have a question.</p>
<h2>Question</h2>
<p dir="auto">I can only get modules to reload on the <em>second</em> time I run a script.</p>
<p dir="auto">For example, here's a project setup:</p>
<pre><code class="language-console">myScript
├── __init__.py
├── myScript.py
└── helpers
    ├── __init__.py
    └── myScriptHelper.py
</code></pre>
<p dir="auto"><code>myScriptHelper.py</code> looks like this:</p>
<pre><code class="language-python">def testReload():
    print("hello, I'm reloaded")
</code></pre>
<p dir="auto">And <code>myScript.py</code> looks like this:</p>
<pre><code class="language-python">import importlib
import helpers
from helpers.myScriptHelper import *

print("hello from myScript")

importlib.reload(helpers.myScriptHelper)
testReload()
</code></pre>
<p dir="auto">So, I would expect to see "hello, I'm reloaded" in the Output Window when I run <code>myScript.py</code>. <em>However,</em> I'm finding that I only end up seeing updates to <code>myScriptHelper.py</code> on the second time I run <code>myScript.py</code> after making any changes.</p>
<h2>Example</h2>
<p dir="auto">I run <code>myScript.py</code>. In the Output, I see this:</p>
<pre><code class="language-console">hello from myScript
hello, I'm reloaded
</code></pre>
<p dir="auto">Next, I change <code>myScriptHelper.py</code> to this:</p>
<pre><code class="language-python">def testReload():
    print("hello, I'm REALLY reloaded")
</code></pre>
<p dir="auto">However, when I run <code>myScript.py</code> again, I see the same output again:</p>
<pre><code class="language-console">hello from myScript
hello, I'm reloaded
hello from myScript
hello, I'm reloaded
</code></pre>
<p dir="auto">It's only when I run <code>myScript.py</code> <em>again a second time</em> that I see the output of the updated module:</p>
<pre><code class="language-console">hello from myScript
hello, I'm reloaded
hello from myScript
hello, I'm reloaded
hello from myScript
hello, I'm REALLY reloaded
</code></pre>
<hr />
<p dir="auto">Have I missed a step, or is it expected that it should take two runs of a script for <code>importlib.reload()</code> to take effect?</p>
<p dir="auto">Thanks for any help here! I know this is a tiny question, but I'm trying to learn how to do the little things right so I can be more effective overall. :)</p>
]]></description><link>https://forum.robofont.com/post/2723</link><guid isPermaLink="true">https://forum.robofont.com/post/2723</guid><dc:creator><![CDATA[ArrowType]]></dc:creator><pubDate>Mon, 04 Nov 2019 09:53:36 GMT</pubDate></item><item><title><![CDATA[Reply to How can I reload a Python module on the *first* attempt? on Mon, 04 Nov 2019 10:18:05 GMT]]></title><description><![CDATA[<p dir="auto">hello <a class="plugin-mentions-user plugin-mentions-a" href="https://forum.robofont.com/uid/445">@ArrowType</a>,</p>
<p dir="auto">to update a module you need to reload it <em>before</em> you import stuff from it:</p>
<pre><code class="language-python">import importlib
import helpers.myScriptHelper
importlib.reload(helpers.myScriptHelper)

from helpers.myScriptHelper import *

print("hello from myScript")
testReload()
</code></pre>
<p dir="auto">also, unless you wish to run some code when the module is imported, you don’t really need to include empty <code>__init__.py</code> files to indicate namespace packages in Python 3.</p>
<p dir="auto">hope this helps! cheers</p>
]]></description><link>https://forum.robofont.com/post/2725</link><guid isPermaLink="true">https://forum.robofont.com/post/2725</guid><dc:creator><![CDATA[gferreira]]></dc:creator><pubDate>Mon, 04 Nov 2019 10:18:05 GMT</pubDate></item><item><title><![CDATA[Reply to How can I reload a Python module on the *first* attempt? on Mon, 04 Nov 2019 15:09:48 GMT]]></title><description><![CDATA[<p dir="auto">Ahhh, that makes sense now.</p>
<p dir="auto">That’s a good tip about <code>__init.py__</code> as well.</p>
<p dir="auto">Thank you so much for your help, Gustavo!</p>
]]></description><link>https://forum.robofont.com/post/2726</link><guid isPermaLink="true">https://forum.robofont.com/post/2726</guid><dc:creator><![CDATA[ArrowType]]></dc:creator><pubDate>Mon, 04 Nov 2019 15:09:48 GMT</pubDate></item></channel></rss>