CR+LF problem

John Roth johnroth at ameritech.net
Thu Jun 20 09:39:29 EDT 2002


"Manuel Ruiz" <mruiz at safa.es> wrote in message
news:3d11bc33.1129927479 at news.mad.ttd.net...
>
> Hi,
>
> ------------------------
> .
> char * txt = "print 123\r\n";
> result = PyRun_Simple( txt, Py_file_input, PyDict_New(), NULL );
> .
> -----------------------
>
> this code fails to exec txt, I got a SyntaxError exception,
> however I if save to file the statement "print 123\r\n" and try to run
> it ussing python interprete (version 2.2.1) It run fine.
>
> Can anyone tell me anything about this rare behaviour
>
> Regards
> Manuel Ruiz

 \r is not a valid character for Python input.

I suspect you're running on a Windows system. When
you saved this to file, the C library would have converted
the \r\n sequence to \n on the readback.

To insert a return, just use \n, regardless of the
system. Python (and C) takes care of the rest, unless
you really need the \r because you're using a network
rather than the file.

Are you sure you didn't mean "print '123'" ?

John Roth





More information about the Python-list mailing list