when using from file import function, how can the importing file be modified to give a desired output without modifying the imported file?
<p>File 1</p>

<pre><code>def multiply():
    x = raw_input('enter the number')
    y = x*4
</code></pre>

<p>File 2</p>

<pre><code>from file1 import multiply
</code></pre>

<p>how do i make the value of <code>x = 4</code> and hence the result <code>(4*4) = 16</code> without user input being implemented when running <code>file2</code>?</p>

<p>There is a straightforward albeit hackey way of achieving what you want. I recommend against it. It is fundamentally a poor design choice, but here it is:</p>

<pre><code>def multiply():
    x = int(raw_input())
    print x * 4

import sys
import io
def force_stdin(f, force_input):
    stdin = sys.stdin
    sys.stdin = io.StringIO(unicode(force_input))
    f()
    sys.stdin = stdin

force_stdin(multiply, '4')
</code></pre>

<p>Output:</p>

<pre><code>16
</code></pre>

python python-2.7