On Thu, 23 Feb 2006 15:59:54 +0100, Franz Steinhaeusler <[EMAIL PROTECTED]> wrote:
>I need it for a file, whose line endings I don't know. > >I wrote for DrPython this script: >(using styled text control and wxPython) and this works, >but I'm looking for a shorter way: ah, sorry, I try to make this more clear again: (DrDocument is instance of a styled text control) import re import string def GetEndOfLineCharacter(): emode = DrDocument.GetEOLMode() if emode == wx.stc.STC_EOL_CR: return '\r' elif emode == wx.stc.STC_EOL_CRLF: return '\r\n' return '\n' text = DrDocument.GetText() eol = GetEndOfLineCharacter() regex = re.compile('\s+' + eol, re.MULTILINE) lines = text.split(eol) new_lines = [] for line in lines: result = regex.search(line + eol) if result != None: end = result.start() new_lines.append (line [:end]) else: new_lines.append(line) newtext = string.join(new_lines, eol) DrDocument.SetText(newtext) -- Franz Steinhaeusler -- http://mail.python.org/mailman/listinfo/python-list