首页 > 解决方案 > 从 html 文件中提取 £(英镑)货币符号和金额 (56)

问题描述

从 html 文件中提取£(英镑)货币符号和金额(56)。它将金额打印为£56并将货币打印为Â。我怎样才能只打印 56,没有符号?它与$标志一起工作正常。

部分代码:

       cost= "£56"  
       currencySymbol = cost[0]
       print (currencySymbol, cost[1:])

我得到的输出:

         Â: £56

标签: eclipsewindows-8currencypython-3.7python-unicode

解决方案


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

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

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

在这里检查(https://ideone.com/Y053Vb


推荐阅读