Skip to content

Instantly share code, notes, and snippets.

@devnoname120
Last active August 29, 2015 14:02
Show Gist options
  • Save devnoname120/ce37f8bb8e24941e5a7f to your computer and use it in GitHub Desktop.
Save devnoname120/ce37f8bb8e24941e5a7f to your computer and use it in GitHub Desktop.
NoPicAds: remove new line character from files
# NoPicAds: remove new line character from files
# https://github.com/legnaleurc/nopicads/
import glob
for fileName in glob.glob("src/sites/*/*.js"):
with open(fileName, "r", encoding='utf-8') as file:
lines = file.readlines()
# If last line is empty
if lines[-1].endswith("\n"):
# Delete it
lines[-1] = lines[-1][:-1]
# Open it in order to overwrite it
file = open(fileName, "w", encoding='utf-8')
# Write back to the file
file.writelines(lines)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment