input function does not work & returns FileInput object
<p>I'm trying to get user input as function call in a small python program but, when i'm using  the <code>input()</code> method, python shell does not let me input anything and quit by itself.</p>

<pre><code>from fileinput import input
def funcinput():
    comm = input("--&gt;")
    print('your input is %s' %comm)

if __name__ == "__main__":
    print("try to get input")
    funcinput()
</code></pre>

<p>Code looks like this and every time I run it, python launcher just give me:</p>

<pre><code>try to get input
your input is &lt;fileinput.FileInput object at 0x10464c208&gt;
&gt;&gt;&gt; 
</code></pre>

<p>without let me input anything</p>

<p>What should I do to make it work?</p>

<p>The cause here is a masking of the built-in <a href="https://docs.python.org/3.6/library/functions.html#input" rel="nofollow"><code>input</code></a>. In some point, a <code>from fileinput import input</code> occurs, which masks <code>builtins.input</code> and replaces it with <a href="https://docs.python.org/3.6/library/fileinput.html#fileinput.input" rel="nofollow"><code>fileinput.input</code></a>. That function doesn't return an <code>str</code> but, instead, returns an instance of <a href="https://docs.python.org/3.6/library/fileinput.html#fileinput.FileInput" rel="nofollow"><code>FileInput</code></a>:</p>

<pre><code>&gt;&gt;&gt; from fileinput import input
</code></pre>

<p>Using <code>input</code> now picks up <code>fileinput.input</code>:    </p>

<pre><code>&gt;&gt;&gt; print(input("--&gt; "))
&lt;fileinput.FileInput at 0x7f16bd465160
</code></pre>

<p>If importing <code>fileinput</code> is <em>necessary</em> import the the module and access the <code>input</code> function using dot notation:</p>

<pre><code>&gt;&gt;&gt; import fileinput
&gt;&gt;&gt; print(fileinput.input("--&gt; ")) # fileinput input, returns FileInput instance.
&gt;&gt;&gt; print(input("--&gt; "))           # original input, returns str
</code></pre>

<p>If this option is failing (or, you have no control of imports for some reason), you could try and delete the imported reference to get the look-up for it to use the built-in version:</p>

<pre><code>&gt;&gt;&gt; from fileinput import input
&gt;&gt;&gt; print(input("--&gt; "))
&lt;fileinput.FileInput at 0x7f16bd465f60&gt;
</code></pre>

<p>Now by deleting the reference with <code>del input</code>:</p>

<pre><code>&gt;&gt;&gt; del input
&gt;&gt;&gt; input("--&gt; ")
--&gt; 
</code></pre>

<p><code>input</code> works as it always does.</p>

python python-3.x input