Created
September 14, 2016 12:39
-
-
Save mirekfranc/fde56397943061ba3b2d424c87e8b754 to your computer and use it in GitHub Desktop.
remove trailing newline at the end of the file / windows tools generate this crap a one needs to be compatible with them
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
if sys.platform == "win32": | |
import os, msvcrt | |
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) | |
if len(sys.argv) < 2: | |
sys.exit(1) | |
with open(sys.argv[1], 'rb') as f: | |
oldline = None | |
for line in f: | |
if oldline: | |
sys.stdout.write(oldline) | |
oldline = line | |
if oldline[-2:] == '\r\n': | |
oldline = oldline[:-2] | |
if oldline[-1:] == '\n': | |
oldline = oldline[:-1] | |
sys.stdout.write(oldline) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment