New submission from Mark Seaborn <[EMAIL PROTECTED]>: compile() raises a SyntaxError if the source code it is given contains trailing spaces or a trailing carriage return character, but this does happen if the same source code is imported or executed.
import subprocess data = "if True:\n pass\n " filename = "/tmp/test.py" fh = open(filename, "w") fh.write(data) fh.close() subprocess.check_call(["python", filename]) subprocess.check_call(["python", "-c", "import test"], cwd="/tmp") compile(data, filename, "exec") This gives: Traceback (most recent call last): File "whitespace.py", line 11, in <module> compile(data, filename, "exec") File "/tmp/test.py", line 3 SyntaxError: invalid syntax This also happens if the data is changed to: data = "if True:\n pass\r" ---------- components: Interpreter Core messages: 75521 nosy: mseaborn severity: normal status: open title: import and compile() do not treat trailing whitespace the same type: behavior versions: Python 2.5 _______________________________________ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue4262> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com