标签:oat filename str ret with open name 处理 imp 没有
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‘))
标签:oat filename str ret with open name 处理 imp 没有
原文地址:https://www.cnblogs.com/endian11/p/9077895.html