python - Can I detect the text codec used in a string? -
i'm reading string file(which can modify) , don't know type of coded string is. there function like
getcodec = mystring.getcodec()
which return like
getcodec = 'utf-8'
or
getcodec = 'ascii'
?
no, there no such function, because files not record codec used write text contained.
if there more context (like more specific format such html or xml) can determine codec because standard specifies default or allows annotating data codec, otherwise reduced guessing based on contents (which tools chardet
do).
for file can modify, have no hope document codec should used.
Comments
Post a Comment