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>In addition to all the above answers, you can run the script as simply <code>./script.py</code> by making the file executable and setting the shebang line, e.g.</p>

<pre><code>#!/usr/bin/python -i
this = "A really boring program"
</code></pre>

<hr>

<p>If you want to use this with the <code>env</code> command in order to get the system default <code>python</code>, then you can try using a shebang like <a href="http://stackoverflow.com/users/5249307/donkopotamus">@donkopotamus</a> suggested in the comments</p>

<pre><code>#!/usr/bin/env PYTHONINSPECT=1 python
</code></pre>

<p>The success of this may depend on the version of <code>env</code> installed on your platform however.</p>

python python-interactive