[英]dealing with foreign characters in python
我在處理像'€'這樣的特殊字符時遇到了問題。
TEXT包含不同貨幣和不同格式的價格
TEXT example:
$ 11.00 USD
$ 9.58 USD
559,89 pуб.
$ 9.58
8,10€
7,05€
8,10€
CDN$ 11.00
22,10 TL
$ 9.58 USD
我試圖將不同的價格分類到不同的列表,
USD = []
RUS = []
EUR = []
TYR = []
CND = []
for link in TEXT:
href = link.text.strip()
if 'USD' in href:
href = href.replace("$","")
href = href.replace(" ","")
href = href.replace("USD","")
href = float(float(href))
USD.append(href)
elif 'pуб' in href:
href = href.replace("pуб","")
href = href.replace(" ","")
href = href.replace(".",",")
href = float(float(href))
RUS.append(href)
elif '€' in href:
href = href.replace("€","")
href = href.replace(" ","")
href = href.replace(".",",")
href = float(float(href))
EUR.append(href)
elif 'TL' in href:
href = href.replace("TL","")
href = href.replace(" ","")
href = float(float(href))
TYR.append(href)
elif 'CND' in href:
href = href.replace("CND$","")
href = href.replace(" ","")
href = float(float(href))
CND.append(href)
else:
print("unknown currency")
但我收到這個錯誤:
SyntaxError: Non-ASCII character '\xd1' in file C:/Users/S/PycharmProjects/untitled1/demo.py on line 26, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
因為它講解了符號:pуб,€...
指定源編碼:
# -*- coding: utf-8 -*-
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.