Created
December 21, 2015 09:37
-
-
Save ladder1984/02246e96e76013eec5e8 to your computer and use it in GitHub Desktop.
清除Windows记事本自动添加的BOM
This file contains hidden or 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
# -*- 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