Skip to content

Instantly share code, notes, and snippets.

@Rembane
Created March 6, 2013 23:05
Show Gist options
  • Save Rembane/5104051 to your computer and use it in GitHub Desktop.
Save Rembane/5104051 to your computer and use it in GitHub Desktop.
Ugliest script ever to remove the BOM from all Python files! :D
#!/usr/bin/env python
import os
for (path, dirs, files) in os.walk(os.getcwd()):
for f in [os.path.join(path, f) for f in files if f.endswith('.py')]:
fh_in = open(f)
if '\xEF\xBB\xBF' in fh_in.read(10):
fh_in.seek(0)
s = fh_in.read().replace('\xEF\xBB\xBF', '')
fh_in.close()
fh_out = open(f, 'w')
fh_out.write(s)
fh_out.close()
else:
fh_in.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment