So, I got this template, they all end in LF, and I can fill in some terms inside with the format and still get LF files, opening with "wb"
These patterns are used in deploying a script on a Windows machine to deploy to a unix server.
The problem is that many people are going to mess with this template, and I'm 100% sure that some of them will put some CRLFs inside.
How could I, using python, convert all crlf to lf?
Thanks.
EDIT
Well, I'm bad, I had an error in my code, opening in "wb" always put lf at the end of lines, even if the file used crlf before.
Here is the code I use if you're interested:
#!/usr/bin/env python # --*-- encoding: iso-8859-1 --*-- import string def formatFile(templatePath, filledFilePath, params, target): openingMode = 'w' if target == 'linux': openingMode += 'b' with open(templatePath, 'r') as infile, open(filledFilePath, openingMode) as outfile: for line in infile: template = string.Template(line.decode('UTF-8')) outfile.write(template.substitute(**params).encode('UTF-8'))
So there are no problems, everything works fine: x
Eildosa
source share