Fixing DOS Line Ends
When I wrote the first edition of this book, I shipped two copies of every example file on the CD-ROM—one with Unix line-end markers and one with DOS markers. The idea was that this would make it easy to view and edit the files on either platform. Readers would simply copy the examples directory tree designed for their platform onto their hard drive and ignore the other one.
If you read Chapter 4, you
know the issue here: DOS (and by proxy, Windows) marks line
ends in text files with the two characters \r\n
(carriage return, line feed), but Unix
uses just a single \n
. Most modern
text editors don’t care—they happily display text files encoded in
either format. Some tools are less forgiving, though. I still
occasionally see the odd \r
character when viewing DOS files on Unix, or an entire file in a
single line when looking at Unix files on DOS (the Notepad accessory
does this on Windows, for example).
Because this is only an occasional annoyance, and because it’s easy to forget to keep two distinct example trees in sync, I adopted a different policy as of the book’s second edition: we’re shipping a single copy of the examples (in DOS format), along with a portable converter tool for changing to and from other line-end formats.
The main obstacle, of course, is how to go about providing a
portable and easy-to-use converter—one that runs “out of the box” on
almost every computer, without changes or recompiles. Some Unix
platforms have commands such as fromdos
and ...
Get Programming Python, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.