This piece of code, file test.py,
if 1:
print \"foo\"
print \"bar\"
can be successfully executed with execfile(\"test.py\
If the pasted content has any empty lines, the interpreter triggers evaluation when encountering them. If any line after an empty line has indentation, it will cause an IndentationError since any previous context has been closed.
Solutions:
Note that spaces vs. tabs does not seem to matter.