Skip to content
Advertisement

Tag: utf-8

Can’t figure out error: “UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xdc in position 0: ordinal not in range(128)”

I have a program that is communicating with another machine that sends (or is supposed to send) ASCII characters, the code below is how I write and read code to the machine. def writeCode(send): address = ‘COM4’ I get the error on the “out+=ser.read(1).decode(‘ascii’) line. I looked online but most of the advice seems to be based around if you

Convert utf-16 to utf-8 using python

I am trying to convert a huge csv file from utf-16 to utf-8 format using python and below is the code: But this code uses lots of memory and fails with Memoryerror. Please help me with an alternate method. Answer an option is to convert the file line by line: or you could open the files with your desired encoding:

Unicode decode mismatch on emojis when using json loads

I have a list of utf-8 encoded objects such as : and decode it as follows: I notice that some emojis are not converted as expected as shown below: However, when I decode an individual string, I get the expected output: I’m not sure why the first approach using json.loads gives an unexpected output. Can someone provide any pointers? Answer

UTF-8 decoding doesn’t decode special characters in python

Hi I have the following data (abstracted) that comes from an API. I’m using the following code to decode the data byte: The cleanhtml is a regex function that I’ve created to remove html tags from the returned data (It’s working correctly). Although, decode(utf-8) is not removing characters like u00e1. My expected output is: I’ve tried to use replace(“\u00e1”, “á”)

How can I read a byte array file of strings?

There is a file with following contents: This is my try to read the lines and convert them to readable utf characters, but still it shows the same strings in the output file: The output file is: As you see, the problem exists for input line but not for target and prediction lines (however scrambled but that’s okay) Answer It

Advertisement