开发者

Is there a package that maintains a list all currencies with symbols?

Is there a python package that provides list of all (or fairly complete) currencies with the s开发者_StackOverflow中文版ymbols (like "$" for USD).

There are excellent pycountry, py-moneyed and ccy but these do not have symbols.


It's a lot more than you really need, but Babel does include currencies, in the Locale currency_symbols dictionary. Some may require a little parsing, though; for example, USD is 'US$' rather than just the dollar sign, while others, like the Euro or Yuan, have no such prefix.

I believe Babel uses the CLDR as its source.


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  ==> ¥

This depends on what locales are installed on your machine. On *nix machines, you can find out what locales are available with the command locale -a.


I created Forex-python package which maintains all latest Currency code and its sign.

>>> from forex_python.converter import CurrencyCodes
>>> c = CurrencyCodes()
>>> print c.get_symbol('GBP')
£

And you can convert amount from one currency to other.

>>> from forex_python.converter import CurrencyRates
>>> c = CurrencyRates()
>>> c.convert('USD', 'INR', 10)
674.73
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜