[英]Remove non ascii characters from a string? (in python)
我正在嘗試從具有多行混合了ascii和非ascii字符的多行的HTML文件中解析一個字符串,例如:
"industrial light & \u003cbr\u003emagic, lucasarts"
我嘗試使用編碼函數將字符串編碼為ascii,但是它只返回與它相同的值。
str = "industrial light & \u003cbr\u003emagic, lucasarts"
str.encode('ascii',errors='ignore')
returns "industrial light & \u003cbr\u003emagic, lucasarts"
任何幫助將不勝感激。
我發現了問題。 我試圖在python 2中對其進行解碼。Python2和python 3對這種轉換的處理方式不同。 一旦我在python 3中嘗試過,一切都可以正常工作。 謝謝大家的幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.