Eclipse 提取£;(英镑)货币符号和html文件中的金额(56)

Eclipse 提取£;(英镑)货币符号和html文件中的金额(56),eclipse,windows-8,currency,python-3.7,python-unicode,Eclipse,Windows 8,Currency,Python 3.7,Python Unicode,从html文件中提取£(英镑)货币符号和金额(56)。它将金额打印为56英镑,并将货币打印为英镑。如果没有符号,我怎么能只打印56?使用$标志可以正常工作 守则的一部分: cost= "£56" currencySymbol = cost[0] print (currencySymbol, cost[1:]) 我得到的输出: Â: £56 有很多方法可以做到这一点,可以使用split、regex和我在下面使用的一种方法: 希望对

从html文件中提取
£
(英镑)货币符号和金额(56)。它将金额打印为
56英镑
,并将货币打印为
英镑
。如果没有符号,我怎么能只打印56?使用
$
标志可以正常工作

守则的一部分:

       cost= "£56"  
       currencySymbol = cost[0]
       print (currencySymbol, cost[1:])
我得到的输出:

         Â: £56

有很多方法可以做到这一点,可以使用split、regex和我在下面使用的一种方法: 希望对你有帮助

import re
cost= "£560,000"
match = re.search(r'([\D]+)([\d,]+)', cost)
output = (match.group(1), match.group(2).replace(',',''))
print (output);

output -->('£', '560000')

check here()

已解决:我在eclipse中尝试在单独的文件中运行以下代码,并给出了关于utf-8的错误。 我搜索了错误并得到了答案,是eclipse改变了unicode样式以避免我以前在python中运行时出现空闲,我想我们可以在eclipse中改变unicode

感谢Martijn Pieters [


不可复制:请显示一个,而不仅仅是其中的一部分。如果您使用更详细的代码上下文完成您的示例,这会有所帮助。最终使用open('file.html',encoding=“UTF-8”)@greg-449解决。我已经在Eclipse中安装了pydev插件。我正在做什么来获取成本符号,即“£”?为什么创建字符组?如何
[\D]
(由同一类别的字符组成的组)不同于
\D
cost= "£56"  
currencySymbol = cost[0]
print (currencySymbol, cost[1:])
#resolution :when using file use encoding
#with open('index.html', encoding="UTF-8") as productFile: