【发布时间】:2016-07-14 14:22:29
【问题描述】:
是否有一个 python 包提供所有(或相当完整的)货币列表带有符号(如美元的“$”)。
有优秀的 pycountry,py-moneyed 和 ccy,但这些没有符号。
【问题讨论】:
-
“符号”是指传统的缩写(如“$”代表美元)吗?
-
是的。将再次更新问题。
标签: python localization currency
是否有一个 python 包提供所有(或相当完整的)货币列表带有符号(如美元的“$”)。
有优秀的 pycountry,py-moneyed 和 ccy,但这些没有符号。
【问题讨论】:
标签: python localization currency
import locale
locales=('en_AG', 'en_AU.utf8', 'en_BW.utf8', 'en_CA.utf8',
'en_DK.utf8', 'en_GB.utf8', 'en_HK.utf8', 'en_IE.utf8', 'en_IN', 'en_NG',
'en_NZ.utf8', 'en_PH.utf8', 'en_SG.utf8', 'en_US.utf8', 'en_ZA.utf8',
'en_ZW.utf8', 'ja_JP.utf8')
for l in locales:
locale.setlocale(locale.LC_ALL, l)
conv=locale.localeconv()
print('{int_curr_symbol} ==> {currency_symbol}'.format(**conv))
# XCD ==> $
# AUD ==> $
# BWP ==> Pu
# CAD ==> $
# DKK ==> kr
# GBP ==> £
# HKD ==> HK$
# EUR ==> €
# INR ==> ₨
# NGN ==> ₦
# NZD ==> $
# PHP ==> Php
# SGD ==> $
# USD ==> $
# ZAR ==> R
# ZWD ==> Z$
# JPY ==> ¥
这取决于您的机器上安装了哪些语言环境。在 *nix 机器上,您可以使用命令 locale -a 找出可用的语言环境。
【讨论】:
Error: unsupported locale setting
我创建了Forex-python 包,它维护所有最新的货币代码及其符号。
>>> from forex_python.converter import CurrencyCodes
>>> c = CurrencyCodes()
>>> print c.get_symbol('GBP')
£
您可以将金额从一种货币转换为另一种货币。
>>> from forex_python.converter import CurrencyRates
>>> c = CurrencyRates()
>>> c.convert('USD', 'INR', 10)
674.73
【讨论】: