Try adding the binary qualifier in your open()
:
with open(scriptFilePath.replace(".py","_UPDATED.py"), mode="wb") as scriptFile:
I notice that your file on pastebin is in DOS format, so it has \r\n
in it. When you call scriptFile.write()
, it translates \r\n
to \r\r\n
, which is terribly confusing.
Specifying "b"
in the open()
will cause scriptfile to skip that translate and write the file is DOS format.
In the alternative, you could ensure that the pastebin file has only \n
in it, and use mode="w"
in your script.