Using the bash shell on Ubuntu Linux and Python 2.7.6, if I run the python script below with the command,
python -i < test.py
>>> >>> ... ... ... File "<stdin>", line 4
SyntaxError: invalid syntax
i = 1
i = 2
$ od -a test.py
0000000 p r i n t sp ' o u t e r ' nl i sp
0000020 = sp 1 nl i f sp T r u e : nl sp p r
0000040 i n t sp ' i n n e r ' nl sp i sp =
0000060 sp 2 nl p r i n t sp i nl
You're having the opposite of the problem in the linked question. The
-i makes python read the script in interactive mode (the ">>> " and "... " are prompts), and in interactive mode, you to press return (i.e. enter a blank line) to exit an indented section. The linked question involved blank lines in the middle of an indented section, which confused the interpreter. You have the opposite: you end an indented section without a blank line. That's perfectly ok in non-intereactive mode, but in interactive mode it's a no-no.
Solution: either put blank lines at the end of indented sections (and never in the middle), don't tell the interpreter to read it in interactive mode. I'm not sure what you're actually trying to accomplish with the
-i flag, but note that
python -i test.py (without the redirect) will run the script in non-interactive mode and then enter interactive mode and read from stdin.