从html文件中提取£(磅)货币符号和金额(56)

问题描述 投票:-1回答:2

从html文件中提取£(磅)货币符号和金额(56)。它打印金额为£56并打印货币为Â。如何只打印56,没有符号?它与$标志工作正常。

部分代码:

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

我得到的输出:

         Â: £56
eclipse windows-8 currency python-3.7 python-unicode
2个回答
0
投票

有很多方法可以做到,你可以使用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')

点击这里(https://ideone.com/Y053Vb


0
投票

已解决:我试图在eclipse中的单独文件中运行下面的代码并给出关于utf-8的错误。我搜索错误并得到答案,是eclipse正在改变unicode风格以避免我曾经在python IDLE中运行,我想我们可以在eclipse中改变unicode?

感谢Martijn Pieters [SyntaxError: Non-UTF-8 code starting with '\x91'

cost= "£56"  
currencySymbol = cost[0]
print (currencySymbol, cost[1:])
#resolution :when using file use encoding
#with open('index.html', encoding="UTF-8") as productFile:
© www.soinside.com 2019 - 2024. All rights reserved.