Changing variable on another module for functions
<p>I have made two py files, in which <strong>main.py</strong> contains:</p>

<pre><code>import module

module.Print("This should not appear.")

module.Silence = False
module.Print("This should appear.")
</code></pre>

<p>The module imported is <strong>module.py</strong> which contains:</p>

<pre><code>Silence = True


def Print(Input, Sil= Silence):
    if Sil == False:
        print(Input)
</code></pre>

<p>The expected result should be:</p>

<blockquote>
  <p>This should appear</p>
</blockquote>

<p>The result:</p>

<blockquote>
  <p></p>
</blockquote>

<p>The issue is that you've defined your <code>Print</code> function with a default argument of True (since <code>Silent == True</code> when this module is imported, and the function created).  Changing the module variable, <code>Silent</code> to False later isn't going to affect this function definition in any way.  It's already set in stone.  </p>

<p>You could achieve what it looks like you want to doing something like (in <code>module.py</code>):</p>

<pre><code>Silence = [True]

def Print(Input, Sil= Silence):
    if Sil[0] == False:
        print(Input)
</code></pre>

<p>...</p>

<p>And then setting <code>module.Silence[0] = False</code> in <code>main.py</code>.</p>

<p>[I'm assuming the goal here was to call the function <em>without</em> passing in an explicit <code>Sil</code> argument.  You can certainly just pass in an explicit second argument and have the function perform exactly how you expect instead]</p>

python python-3.x variables import