pythonencodingmbcs

MBCS encoding unknown


I'm trying to open a file with MBCS encoding in Python but I'm getting an error.

If I write:

fileIN = open(filename, "r", encoding = "mbcs")

I get:

Traceback (most recent call last):
 File "/data/stru0039/Rotation/test.py", line 144, in <module>
   fileIN = open(filename, "r", encoding = "mbcs")
LookupError: unknown encoding: mbcs

Is there a way to install this codec? Thanks!


Solution

  • The mbcs encoding is only available on Windows. It refers to whatever the current Windows "ANSI" code page (CP_ACP) is.¹

    If you are not running it on Windows, just guess an encoding and use it. If you are running it on Windows but through something like MSYS2 or Cygwin, you get a bug to report since someone is failing to detect the underlying Windows API.


    ¹ For those reading this answer, it's probably not an MBCS, but just a single-byte encoding like CP1252 (most similar to ISO-8859-1).