Skip to content

Instantly share code, notes, and snippets.

@ladder1984
Created December 21, 2015 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ladder1984/02246e96e76013eec5e8 to your computer and use it in GitHub Desktop.
Save ladder1984/02246e96e76013eec5e8 to your computer and use it in GitHub Desktop.
清除Windows记事本自动添加的BOM
# -*- coding: utf-8 -*-
# 清除Windows记事本自动添加的BOM
def clean_bom(file_name):
with open(file_name, 'r+') as f:
content = f.read()
content = re.sub(r"\xfe\xff", "", content)
content = re.sub(r"\xff\xfe", "", content)
content = re.sub(r"\xef\xbb\xbf", "", content)
f.seek(0)
f.write(content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment