On 1/11/2010 3:02 PM, Jeremy wrote:

I am using the re.sub command to remove trailing whitespace from lines
in a text file.

>>> help(str.rstrip)
Help on method_descriptor:

rstrip(...)
    S.rstrip([chars]) -> str

    Return a copy of the string S with trailing whitespace removed.
    If chars is given and not None, remove characters in chars instead.

Should be mush faster.

 The commands I use are copied below.  If you have any
suggestions on how they could be improved, I would love to know.

Thanks,
Jeremy

lines = self._outfile.readlines()
self._outfile.close()

line = string.join(lines)

if self.removeWS:
     # Remove trailing white space on each line
     trailingPattern = '(\S*)\ +?\n'
     line = re.sub(trailingPattern, '\\1\n', line)


--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to