Hi Folks,


I'm totally at a loss with this one... The code is supposed to open a file (postscript with UNIX LF-only EOL characters), look for and change a line, then write the lines back. It works fine, except for the fact that I can't dissuade Python from writing CRLF as the EOL character, and the onward system that's taking it as an input won't read it with CRLF. I've tried to strip the EOL completely and explicitly write '/n', but it always adds the CR as well. I've tried stripping the lines, replacing '/r' with '', pretty much every basic string manipulation I get think of, although I'm aware that I'm manipulating the string and then writing it, so if it's the write operation that causes the problem then it may do no good anyway.

I've also tried opening and writing the file as binary, but I get a stream of problems like "TypeError: Can't convert '_io.TextIOWrapper' object to str implicitly" and so on.

Files goes in with LF, surely there should be some way of writing it back with LF!?!

Any help appreciated.

inputfile = open(inpath + "\\" + file, "r")
outputfile = open(temppath + "\\" + "modified--" + file, "w")

for line in inputfile:
 if preDelimField in line:
  modifiedline = line[:len(preDelimField) + 2] + '(' + prefix + ')' + ' def'

 elif postDelimField in line:
  modifiedline = line[:len(postDelimField) + 2] + '(' + suffix + ')' + ' def'


This question has already been answered. Start a new discussion instead.