Message75521
| Author |
mseaborn |
| Recipients |
mseaborn |
| Date |
2008年11月05日.10:56:27 |
| SpamBayes Score |
1.9570339e-09 |
| Marked as misclassified |
No |
| Message-id |
<1225882648.97.0.627285996609.issue4262@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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" |
|
History
|
|---|
| 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 |
|