Apr-23-2024, 09:15 AM
(Apr-23-2024, 08:49 AM)Winfried Wrote: Is try/except the right way to do it?Normally, there is no way to decode a file having an unknown unicode encoding. Specialized modules such as chardet contain tools to guess the encoding of a file. It is probably the best solution, but read the FAQ of the chardet module first.
Python is not equipped with tools to guess encodings, so attempting to decode and catch exceptions will succeed in diagnosing that some encodings are not the actual encoding of the file, but a success does not mean that it is the correct encoding an the result can be a mojibake
« We can solve any problem by introducing an extra level of indirection »