Printing unix Line endings from Windows.

Ant antroy at gmail.com
Tue Dec 5 07:08:30 EST 2006


John Machin wrote:

> Ant wrote:
...
> > filehandle.write("xxx \n")
> > filehandle.write("xxx \x0a")
> >
> > and all of these give me a nice windows-style crlf!
> >
> > Surely there must be a way to do this ...
>
> and there is: open your output file in binary mode; then it won't
> convert every \n to \r\n.
...
> | >>> '\n' is '\x0a'
> | True

(and F wrote something very similar.)

Cheers guys. Shame that fileinput doesn't take an argument to specify
the write mode when  'inplace'  is True, because it is otherwise makes
editing multiple files in place very simple.

Is it worth me submitting a patch to fileinput which can take an
optional write mode parameter?

Cheers,




More information about the Python-list mailing list