Skip to content

Instantly share code, notes, and snippets.

@gzxultra
Forked from binderclip/check_if_file_utf_8.py
Created May 22, 2016 06:05
Show Gist options
  • Save gzxultra/fcf9479f4f7b0ac341a271bd25422002 to your computer and use it in GitHub Desktop.
Save gzxultra/fcf9479f4f7b0ac341a271bd25422002 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
@gzxultra
Copy link
Author

gzxultra commented Jun 2, 2016

$ 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