【问题标题】:Python library to convert full currency names to their appropriate abbreviationPython 库,用于将完整的货币名称转换为其适当的缩写
【发布时间】:2021-10-14 03:23:50
【问题描述】:

我有一个货币列表:

       'United States dollar', 'European Euro', 'Indian rupee',
       'Pound sterling', 'Canadian dollar', 'Brazilian real',
       'Australian dollar', 'Polish zloty', 'Russian ruble', 'Swedish krona',
       ...
       'Macanese pataca', 'Samoan tala', 'Libyan dinar', 'Namibian dollar',
       'Cayman Islands dollar', 'Fijian dollar', 'Lesotho loti',
       'Turkmen manat', 'Somali shilling', 'Mozambican metical'

他们是否有任何现有的库可以帮助我将这些名称转换为正确的缩写 例如:

United States dollar -- USD
European Euro -- EUR
Indian Rupee -- INR etc

【问题讨论】:

    标签: python currency


    【解决方案1】:

    您可以利用此 JSON 数据查找缩写和符号 https://gist.github.com/stevekinney/8334552。 通过这个,你可以遍历数据,可以很容易地找到符号和缩写及其名称。

    【讨论】:

      【解决方案2】:

      是的,这个图书馆iso4217parse

      例如-

      a = 'United States dollar'
      text = iso4217parse.by_symbol_match(a.strip())
      
      text
      [Currency(alpha3='USD', code_num=840, name='United States dollar', 
      symbols=['US$', '$', '$', '﹩', 'dollar', 'dollars', 'Dollar', 
      'Dollars', 'US$', 'US﹩'], minor=2, countries=['AS', 'BB', 'BM', 'BQ', 
      'EC', 'FM', 'GU', 'HT', 'IO', 'MH', 'MP', 'PA', 'PR', 'PW', 'SV', 'TC', 
      'TL', 'UM', 'US', 'VG', 'VI'])]
      
      currency = str(text[0][3][1])+' '+str(text[0][2])
      

      输出-

      '$ United States dollar' 
       # in the current case, the text variable will need
       # to be parsed in order to get alpha3='USD'
      

      虽然,测试它为几种货币提供的输出,很少根据项目要求为符号提供不同的货币。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-07-07
        • 2014-12-31
        • 1970-01-01
        • 1970-01-01
        • 2020-10-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多