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

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -