[Idle-dev] preserving newline representation in source files

Guido van Rossum guido@python.org
Fri, 03 Jan 2003 12:32:47 -0500


> Working in a mixed Unix/Windows environment, I note that whenever I
> push a python source file from my Unix machine to my Windows machine,
> use Idle to modify it on the Windows machine, and then push it back to
> the Unix machine, it now has the Windows newline representation.
> 
> This behavior is entirely plausible and straightforward, but there is
> an alternative treatment, which emacs uses, that I think is more
> useful: When emacs reads a file, it remembers the newline convention
> that the file uses, and preserves that convention when it writes the
> file back.
> 
> I wonder -- has anyone considered such behavior for a future Idle version?

Until recently this would have been a pain.  As of Python 2.3, it can
be done quite conveniently using universal newlines,
open(filename,"U"), and the new 'newlines' attribute of resulting file
objects.

--Guido van Rossum (home page: http://www.python.org/~guido/)