How to write an interactive shell in Python?
<p>Is it <strong>possible</strong> to run python script as if it's a command line interpreter, Example :</p>

<pre><code>from sys import argv

argv=argv[1:]
str=''.join(argv)
import os
def ls():
    x=os.listdir(os.getcwd())
    for file in x:
        print(file)
if str =='ls':
    ls()
</code></pre>

<p>in this case I used argv to pass arguments, but can I want the code to behave like a command line interpreter and call my functions example:</p>

<p>myscript> ls
file.py
myscript></p>

<p><strong>Note</strong> :Sorry if i didn't explain my idea clearly, English is not my native language.</p>

<p><strong>Update</strong> : some people said my question is duplicated and the same question of <a href="https://stackoverflow.com/questions/1934675/how-to-execute-python-scripts-in-windows">this</a> but i repeat , I want to make "interactive shell" not "How to execute Python scripts in Windows"</p>