I have Python 2 code which looks like example a), and I think about whether I should leave it for Python 3 or convert it to binary and writing it in binary mode.
from datetime import datetime # a with open("check.log", "a") as f: content = "started at: %s\n" % datetime.today() f.write(content) # b with open("check.log", "ab") as f: content = "started at: %s\n" % datetime.today() content = content.encode("utf-8") f.write(content)
With both ways the text in the file looks the same. At least on my Ubuntu dev machine.
I’d appreciate any insight why this possible does not make any difference - or maybe when this makes a difference.