Hi David,
2005/11/10, David Douard <[EMAIL PROTECTED]>:
> Note this is naive, since it will replace any instance of the '\r\n'
> characters, but they may appear inside of a string, in which case they
> should not be replaced.
no that's not really the case since strings containing those escape
literals are transformed by Python as raw strings with another leading
backslash to distinguish them between real control characters in a
stream.
Every Python standard distribution actually comes with a standard
script for this.
It's
<code>
#! /usr/bin/env python
"Replace CRLF with LF in argument files. Print names of changed files."
import sys, os
def main():
for filename in sys.argv[1:]:
if os.path.isdir(filename):
print filename, "Directory!"
continue
data = open(filename, "rb").read()
if '\0' in data:
print filename, "Binary!"
continue
newdata = data.replace("\r\n", "\n")
if newdata != data:
print filename
f = open(filename, "wb")
f.write(newdata)
f.close()
if __name__ == '__main__':
main()
</code>
and can be used from the shell by passing the file names as arguments.
However, I am not absolutely sure if there are some situations where
there really would be some conflict.
--
Best Regards
Christian Junker
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]