Python decode unknown character

2024/10/5 19:20:53

I'm trying to decode the following: UKLTD� For into utf-8 (or anything really) but I cannot workout how to do it and keep getting errors like

'ascii' codec can't decode byte 0xae in position 8: ordinal not inrange(128)

I'm reading from a csv and have the following:

with open(path_to_file, 'rb') as f:reader = csv.reader(f)for row in reader:order = Order(...product_name = row[11].encode('utf-8'),...)order.save()

I would be happy right now to just ignore the character if I have keep the rest of the string.

Answer

Thank you to @BartFriederichs.

Solution is : product_name = row[11].decode('iso-8859-1').encode('utf8')

https://en.xdnf.cn/q/119544.html

Related Q&A

UnboundLocalError: TRY EXCEPT STATEMENTS

I am currently creating a menu with try except tools. Im trying to create it so if a user enters nothing (presses ENTER) to output:You have not entered anything, please enter a number between 1 and 4Th…

Cant load music into pygame

please help if you can. Cant seem to be able to upload music into my game in progress. It comes up with the error of "cant load"... Would be great if someone got back to me quick, This is a m…

C# Socket: how to keep it open?

I am creating a simple server (C#) and client (python) that communicate using sockets. The server create a var listener = new Socket(AddressFamily.InterNetwork,SocketType.Stream, ProtocolType.Tcp)then …

Python Selenium - how to get confirmation after submit

I have a follow up question on this post, I want to get any confirmation text after I hit submit button. Either the code works or not. html - invalid example <div class="serialModalArea js-seri…

Assigning a input on a line to its line number?

I was having a go at the following problem from the AIO (Australian Informatics Olympiad) Training Problems Site (Question in Italics and specifics in bold, my attempt below): The Problem Encyclopaedia…

Create a new list according to item value

I have a list like below. [T46, T43, R45, R44, B46, B43, L45, L44, C46, C45]where I want to group according to int value:[id][ , , , , ] # AREA PATTERN [Top, Right, Bottom, Left, Center][46][1,0,1…

Concatenating many time and date columns

I have many date and time column pairs (around 15 each) that share the same prefix, ie. SH or DEL. The columns are all of dtype object, ie. string. All the columns belong to the same Dataframe. Here is…

Python with ICS files and CSV [duplicate]

This question already has answers here:Parsing files (ics/ icalendar) using Python(6 answers)Closed 5 years ago.one friend ask me some help on a personnal project, but I have to admit my skills in Pyth…

loading my data in numpy genfromtxt get errors

I have my data file contain 7500 lines with :Y1C 1.53 -0.06 0.58 0.52 0.42 0.16 0.79 -0.6 -0.3 -0.78 -0.14 0.38 0.34 0.23 0.26 -1.8 -0.1 -0.17 0.3…

Install dlib with cuda support ubuntu 18.04

I have CUDA 9.0 and CUDNN 7.1 installed on Ubuntu 18.04(Linux mint 19). Tensorflow-gpu works fine on GPU(GTX 1080ti).Now i am trying to build dlib with CUDA support:sudo python3 setup.py install --yes …