Python decode unknown character

喜你入骨 提交于 2019-12-13 07:49:55

问题


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 in range(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.


回答1:


Thank you to @BartFriederichs.

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



来源:https://stackoverflow.com/questions/47941623/python-decode-unknown-character

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!