Removing non-ascii characters from any given stringtype in Python

前端 未结 2 1931
清歌不尽
清歌不尽 2021-02-10 18:55
>>> teststring = \'aõ\'
>>> type(teststring)

>>> teststring
\'a\\xf5\'
>>> print teststring
aõ
>>> test         


        
2条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-10 19:29

    It's simple: .encode converts Unicode objects into strings, and .decode converts strings into Unicode.

提交回复
热议问题