python i18n

  • 现在pygal已经没有i18n模块,要改用pygal_maps_world.i18n(pycharm直接安装)
  • import json
    from pygal_maps_world.i18n import COUNTRIES
    
    
    fileName = "population_data.json"
    with open(fileName) as f:
        pop_data = json.load(f) # json.load()将数据转化为python能够处理的格式,这里是一个列表
    
    for pop_dict in pop_data:
        if pop_dict['Year'] == '2010':
            country_name = pop_dict["Country Name"]
            population = int(float(pop_dict['Value']))
            print(country_name + ':' + str(population))
    
    
    def get_country_code(country_name):
        for code, name in COUNTRIES.items():
            if name == country_name:
                return code
        return None
    
    
    print(get_country_code('Andorra'))
    

      

猜你喜欢

转载自www.cnblogs.com/endian11/p/9077895.html