What's the u prefix in a Python string?

前端 未结 6 1034
南笙
南笙 2020-11-21 22:45

Like in:

u\'Hello\'

My guess is that it indicates \"Unicode\", is it correct?

If so, since when is it available?

6条回答
  •  太阳男子
    2020-11-21 23:34

    I came here because I had funny-char-syndrome on my requests output. I thought response.text would give me a properly decoded string, but in the output I found funny double-chars where German umlauts should have been.

    Turns out response.encoding was empty somehow and so response did not know how to properly decode the content and just treated it as ASCII (I guess).

    My solution was to get the raw bytes with 'response.content' and manually apply decode('utf_8') to it. The result was schöne Umlaute.

    The correctly decoded

    für

    vs. the improperly decoded

    fĂźr

提交回复
热议问题