How to get a python script to invoke "python -i" when called normally?
<p>I have a python script that I like to run with <code>python -i script.py</code>, which runs the script and then enters interactive mode so that I can play around with the results.</p>

<p>Is it possible to have the script itself invoke this option, such that I can just run <code>python script.py</code> and the script will enter interactive mode after running?</p>

<p>Of course, I can simply add the <code>-i</code>, or if that is too much effort, I can write a shell script to invoke this.</p>

<p>I think you're looking for <a href="https://docs.python.org/3/library/code.html#code.interact" rel="nofollow" title="code.interact">this</a>?</p>

<pre class="lang-py prettyprint-override"><code>import code
foo = 'bar'
print foo
code.interact(local=locals())
</code></pre>

python python-interactive