Script runs strangely in interpreter. What is the effect of the -i flag?
<p>I recently made a program which prints a word diagonally. Whenever I go to the console/python interpreter and type </p>

<p><code>python3 "xxx.py"</code>, it will just continue onto the next line and won't do anything.</p>

<p>However, if I do: <code>python3 -i "xxx.py"</code> it enters python and lets me enter inputs for my program</p>

<p>Why is this happening?</p>

<p>My code (copied from comment below):</p>

<pre><code>def diagonal(text, right_to_left = False):
    #Code for diagonal

diagonal()
</code></pre>

<p>I got this error:</p>

<pre><code>Traceback (most recent call last): File "question1.py", line 17, in &lt;module&gt; diagonal() 
TypeError: diagonal() missing 1 required positional argument: 'text'
</code></pre>

<p>The flag <code>-i</code> tells python to process the script, and then enter interactive mode. Without the <code>-i</code> python will just process the script and then exit.</p>

<p>A script might define functions, classes etc, but not call them. If you want the script to do something, you must have at least one line in your script that calls a function.</p>

<p>The usual pattern is:</p>

<pre><code>#class and function definitions 
def print_diagonal(x):
    #code for diagonal

def main():
    #code for running the program
    word = input()
    print_diagonal(word)

#run the program
main()
</code></pre>

<p>The error you get is because the diagonal function has one required argument, the text. You need to supply this argument in some way. You could use an <code>input</code> function in the code (as in my example), or you could use the command line by <code>import sys</code>, and reading <code>sys.argv[]</code>. The <a href="https://docs.python.org/3/library/sys.html?highlight=sys.argv#sys.argv" rel="nofollow">python documentation</a> has examples of this</p>

python