Message75521
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" |
|
Date |
User |
Action |
Args |
2008-11-05 10:57:29 | mseaborn | set | recipients:
+ mseaborn |
2008-11-05 10:57:28 | mseaborn | set | messageid: <1225882648.97.0.627285996609.issue4262@psf.upfronthosting.co.za> |
2008-11-05 10:56:28 | mseaborn | link | issue4262 messages |
2008-11-05 10:56:27 | mseaborn | create | |
|