I came across a situation today to find out what kind of a encoding a file is using. I want to understand the encoding because if I process the text file without that, the results might change. My search on Internet made me land at http://poshcode.org/2153 which gave a nice script for identifying the encoding of a given file.
You can get complete code from http://poshcode.org/2153