Mute printing of an imported Python script
<p>I want to import a python script in to another script. </p>

<pre><code>$ cat py1.py
test=("hi", "hello")

print test[0]

$ cat py2.py
from py1 import test

print test
</code></pre>

<p>If I execute <code>py2.py</code>:</p>

<pre><code>$ python py2.py 
hi
('hi', 'hello')
</code></pre>

<p>Can I anyway mute the first <code>print</code> which is coming from the <code>from py1 import test</code>?</p>

<p>I can't comment the <code>print</code> in <code>py1</code>, since it is being used somewhere else. </p>

<p>You could implement this functionality with methods:</p>

<p><code>py1.py</code></p>

<pre><code>test=("hi", "hello")

def print_test():
    print(test)

def print_first_index():
    print(test[0])
</code></pre>

<p><code>py2.py</code></p>

<pre><code>import py1
py1.print_test()
</code></pre>

<p>As MooingRawr pointed out, this would require you to change whichever classes use <code>py1.py</code> to import it and call the <code>py1.print_first_index()</code> function which may not be to your liking.</p>

python