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

懵懂的女人 提交于 2020-01-12 14:32:07

问题


Is there a python package that provides list of all (or fairly complete) currencies with the symbols (like "$" for USD).

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


回答1:


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.




回答2:


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.




回答3:


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


来源:https://stackoverflow.com/questions/7248694/is-there-a-package-that-maintains-a-list-all-currencies-with-symbols

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!