Replace special characters in python

后端 未结 2 1285
迷失自我
迷失自我 2021-01-06 14:15

I have some text coming from the web as such:

£6.49

Obviously I would like this to be displayed as:

£6.49

I have tried the following so far:

2条回答
  •  鱼传尺愫
    2021-01-06 15:12

    Edit: you have your objects already in unicode. Seems to me there is no reason to actually use enocde/decode at all.

    >>> print u'Oscar Winners Best Pictures Box Set \xc2\xa36.49'.replace(u'Â','')
    Oscar Winners Best Pictures Box Set £6.49
    

    However it seems to me that something is wrong there. The unicode objects are actually not unicode; see:

    >>> print 'Oscar Winners Best Pictures Box Set \xc2\xa36.49'.decode('utf8')
    Oscar Winners Best Pictures Box Set £6.49
    

    The repr() you posted should not be unicode object. That's why I was asking where are you getting the data, there is something wrong.

提交回复
热议问题