How To/python/

#!python
"""
on windows new line (line_feed) character (0x0a , \n) is converted to carriage_return + line_feed (0x0d 0x0a , \r\n)
when string is written to file. The solution is to use "wb" flag when opening file.
"""
 
file = open("file.txt", "w")  # Wrong!
file = open("file.txt", "wb") # Good