Hello
Does anybody know how to get the encoding of a file in Python. I know that you can use the codecs module to open a file with a specific encoding but you have to know it in advance.
import codecs
f = codecs.open("file.txt", "r", "utf-8")
Is there a way to detect automatically which encoding is used for a file?
Thanks in advance
Edit: Thanks everybody for very interesting answsers. You may also be interested by http://whatismyencoding.com/ which is based on chardet (more over the site is powered by bottle python framework)