php system, python and utf-8

后端 未结 2 1141
一向
一向 2021-01-14 12:44

I have a python program running very well. It connects to several websites and outputs the desired information. Since not all websites are encoded with utf-8, I am requestin

2条回答
  •  离开以前
    2021-01-14 12:59

    When you run the python script in your terminal, your terminal is likely to be encoded in UTF8 (specially if you are using linux or mac).

    When you set l variable to "some string with latin characters", that string will be encoded to the default encoding, if you are using a terminal l will be UTF8 and the script wont crash.

    A little tip: if you have a string encoded in latin1 and you want it in unicode you can do:

    variable.decode('latin1')

提交回复
热议问题