line break confusion

Michael Mell mike at nthwave.net
Sat Feb 16 03:37:57 CET 2002


Using Python 2.2 running on any arbitrary OS (Linux, Win, Mac), I want
to
    1) read several files having an arbitrary mix of line break types
(Linux, Win, Mac)
    2) then standardize the breaks of each of the files to a single type
and
    3) then concatenate them all into a string for writing.

Problems:
Linux and Mac:
    I have not found the magic string which represents the Windows line
break on Linux or Mac. Neither '\r\n', nor '\n\r' works.
Mac:
    It seems that RETURN and NEWLINE are swapped: an '\r' creates Linux
breaks, an '\n' creates Mac breaks.


In the string module, whitespace = ' \t\n\r\v\f' (5 characters here).
Yet, when I run this:
>>> import string
>>> for c in string.whitespace:
>>>     print '.'+ c + '.'

I get 7 results.
What's going on here?

Thanks
Mike


--
mike at nthwave.net
llemekim         YahooIM
415.455.8812     voice
419.735.1167     fax






More information about the Python-list mailing list