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

后端 未结 3 1319
广开言路
广开言路 2021-02-20 11:36

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

There are excellent pycount

相关标签:
3条回答
  • 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.

    0 讨论(0)
  • 2021-02-20 12:11
    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.

    0 讨论(0)
  • 2021-02-20 12:11

    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 讨论(0)
提交回复
热议问题