Skip to content

Instantly share code, notes, and snippets.

@binderclip
Created May 11, 2016 14:52
Show Gist options
  • Save binderclip/0db66d3f26aaec5ecf8aa5584f221d63 to your computer and use it in GitHub Desktop.
Save binderclip/0db66d3f26aaec5ecf8aa5584f221d63 to your computer and use it in GitHub Desktop.
simple python script check if file utf-8 coding
import sys
def main():
if len(sys.argv) < 2:
print 'please enter file path'
file_path = sys.argv[1]
with open(file_path, 'r') as f:
s = f.read()
try:
s.decode('utf-8')
except:
print '%s not utf-8' % sys.argv[1]
# print 'finish~~'
if __name__ == '__main__':
main()
# print sys.argv
@binderclip
Copy link
Author

$ python2 check_if_file_utf_8.py <file-to-test>
$ find . -name '*.py' | xargs -L1 python2 check_if_file_utf_8.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment