This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mseaborn
Recipients mseaborn
Date 2008-11-05.10:56:27
SpamBayes Score 1.9570339e-09
Marked as misclassified No
Message-id <>
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/"
fh = open(filename, "w")
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 "", line 11, in <module>
    compile(data, filename, "exec")
  File "/tmp/", 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:29mseabornsetrecipients: + mseaborn
2008-11-05 10:57:28mseabornsetmessageid: <>
2008-11-05 10:56:28mseabornlinkissue4262 messages
2008-11-05 10:56:27mseaborncreate