Skip to content

Instantly share code, notes, and snippets.

@Park-Developer
Created September 2, 2021 16:08
Show Gist options
  • Save Park-Developer/263c71f3959c89787711989bdc16ba40 to your computer and use it in GitHub Desktop.
Save Park-Developer/263c71f3959c89787711989bdc16ba40 to your computer and use it in GitHub Desktop.
check file encoding type
def decide_encoding(file_path):
try:
print("UTF-8")
f = open(file_path, 'r', encoding='utf-8') #ansi
txtdata = f.readlines()
return (True,"utf-9")
except:
try:
print("ANSI")
f = open(file_path, 'r', encoding='ansi') # ansi
txtdata = f.readlines()
return (True, "ansi")
except:
try:
print("cp949")
f = open(file_path, 'r', encoding='cp949') # ansi
txtdata = f.readline()
return (True, "cp949")
except:
return (True, None)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment