exec(formula) does not like embedded "\r" in linux?

Ernie eadorio at yahoo.com
Sat Jul 24 23:17:11 EDT 2004


Hi,

I spent more than an hour wondering why the following works in my
Python 2.3.4 Linux box:

formula = """
def dummy():
    print "This is Ok!"
"""

exec(formula)
dummy()

but if I receive a formula string from a textarea in an HTML form page
using the cgi library, the  exec(formula) raises an error. Inspecting
the formula string, the line terminators used were "\r\n"s.
Translating these line terinators back to "\n" fixed the problem.

Should not exec() be happy to process these "\r\n" as easily as "\r"
without errors in linux?  Is this a bug?

Regards,

Ernie



More information about the Python-list mailing list