Python Forum
Right way to open files with different encodings?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Right way to open files with different encodings?
#2
(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 »
Reply


Messages In This Thread
RE: Right way to open files with different encodings? - by Gribouillis - Apr-23-2024, 09:15 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Open files in an existing window instead of new Kostov 2 493 Apr-13-2024, 07:22 AM
Last Post: Kostov
  open python files in other drive akbarza 1 823 Aug-24-2023, 01:23 PM
Last Post: deanhystad
  How to open/load image .tiff files > 2 GB ? hobbyist 1 2,582 Aug-19-2021, 12:50 AM
Last Post: Larz60+
  Open and read multiple text files and match words kozaizsvemira 3 6,900 Jul-07-2021, 11:27 AM
Last Post: Larz60+
Question (solved) open multiple libre office files in libre office lucky67 5 3,557 May-29-2021, 04:54 PM
Last Post: lucky67
  Can't open files Lass86 5 2,614 Nov-10-2020, 07:18 PM
Last Post: jefsummers
  Using Python to loop csv files to open them Secret 4 2,891 Sep-13-2020, 11:30 AM
Last Post: Askic
  Find specific subdir, open files and find specific lines that are missing from a file tester_V 8 3,839 Aug-25-2020, 01:52 AM
Last Post: tester_V
  ModuleNotFoundError: no module named 'encodings' grunge10111 1 3,948 May-29-2020, 02:22 AM
Last Post: Larz60+
  subprocess.Popen() and encodings voltron 0 5,886 Feb-20-2020, 04:57 PM
Last Post: voltron

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020