Mav*_*ick 8 python django python-2.7 django-1.5 django-countries
我django_countries用来显示国家列表.现在,我有一个要求,我需要根据国家显示货币.挪威 - 挪威克朗,欧洲和非洲(除英国外) - 欧元,英国 - 英镑,美国和亚洲 - 美元.
这可以通过django_countries项目实现吗?或者我可以使用python或django中的其他软件包吗?
任何其他解决方案也受到欢迎.
---------------------------更新-------------主要重点在于获得很多解决方案:
Norway - NOK, Europe & Afrika (besides UK) - EUR, UK - GBP, AMERICAS & ASIA - USDs.
---------------------------- SOLUTION --------------------- -----------
我的解决方案很简单,当我意识到我无法获得任何ISO格式或包来获得我想要的东西时,我想编写自己的脚本.它只是一个基于条件的逻辑:
from incf.countryutils import transformations
def getCurrencyCode(self, countryCode):
continent = transformations.cca_to_ctn(countryCode)
# print continent
if str(countryCode) == 'NO':
return 'NOK'
if str(countryCode) == 'GB':
return 'GBP'
if (continent == 'Europe') or (continent == 'Africa'):
return 'EUR'
return 'USD'
Run Code Online (Sandbox Code Playgroud)
不知道这是否有效,想听听一些建议.
感谢大家!
ale*_*cxe 13
那里有几个模块:
import pycountry
country = pycountry.countries.get(name='Norway')
currency = pycountry.currencies.get(numeric=country.numeric)
print currency.alpha_3
print currency.name
Run Code Online (Sandbox Code Playgroud)
打印:
NOK
Norwegian Krone
Run Code Online (Sandbox Code Playgroud)import moneyed
country_name = 'France'
for currency, data in moneyed.CURRENCIES.iteritems():
if country_name.upper() in data.countries:
print currency
break
Run Code Online (Sandbox Code Playgroud)
版画 EUR
import money
country_name = 'France'
for currency, data in money.CURRENCY.iteritems():
if country_name.upper() in data.countries:
print currency
break
Run Code Online (Sandbox Code Playgroud)
版画 EUR
pycountry定期更新,py-moneyed看起来很棒,功能多python-money,python-money现在还没有维护.
希望有所帮助.
| 归档时间: |
|
| 查看次数: |
4523 次 |
| 最近记录: |