August 2018
Intermediate to advanced
366 pages
10h 14m
English
If you're wondering how it might be possible to read a file for which the encoding is unknown, well, that's a far more complex problem.
The fact is that unless the file provides some guidance in a header, or something equivalent, that can tell you the type of encoding on the content, there is no reliable way to know how a file might be encoded.
You might try multiple different types of encoding and check which one is able to decode the content (doesn't throw UnicodeDecodeError), but the fact that a set of bytes decodes to an encoding doesn't guarantee that it decodes to the right result. For example, the 'ì' character encoded to utf-8 decodes perfectly in latin-1, but results in a totally different thing:
>>> 'ì'.encode('utf-8').decode('latin-1') ...