end of lines

Eric Mattes ericmattes at yahoo.com
Tue Jan 28 17:35:07 CET 2003


Hi.

I am running Windows XP and activestate python 2.2.1. I'm writing a
program that reads in a (local) file using urllib and the readlines()
method like so:

code = "".join(urllib.urlopen(file).readlines())
string.replace(code, "\r", "\n")
compiled_code = compile(code, '<string>', 'exec')

This causes a SyntaxError "Invalid Syntax" with an arrow pointing at
the end of the first line of the string read from the file. For
example, the file's first line is:

print "hi"

The error will point to the space just after the "hi"

I read that the exec and compile functions need lines to end with only
a newline character, so I put that replace call in there to filter out
the CRs. It still
doesn't work! I am really stumped by this one. Any help would be
appreciated.

Thanks!
-Eric




More information about the Python-list mailing list