def get_country(country): try: a = list(COUNTRIES.keys())[list(COUNTRIES.values()).index(country)] except Exception: return None else: return a
class World(BaseMap): """Worldmap graph""" x_labels = list(COUNTRIES.keys()) area_names = COUNTRIES area_prefix = '' svg_map = WORLD_MAP kind = 'country' @cached_property def countries(self): return [ val[0] for serie in self.all_series for val in serie.values if val[0] is not None ] @cached_property def _values(self): """Getter for series values (flattened)""" return [ val[1] for serie in self.series for val in serie.values if val[1] is not None ]
"""Countries.py""" from pygal_maps_world.i18n import COUNTRIES for country_code in sorted(COUNTRIES.keys()): print(country_code, COUNTRIES[country_code])
from pygal_maps_world.i18n import COUNTRIES for country_code in sorted(COUNTRIES.keys()): print(country_code, COUNTRIES[country_code])
from pygal_maps_world.i18n import COUNTRIES # print(COUNTRIES) for k in COUNTRIES.keys(): print(k + ":" + COUNTRIES[k])
def print_code_name(): #pygal绘图时使用的是两个字母的国别码,而文件里使用的是三个 #字母,因此需要使用i18n模块进行转换。先打印国别码和国家名: for country_code in sorted(COUNTRIES.keys()): print(country_code, COUNTRIES[country_code])
import pygal from pygal_maps_world.i18n import COUNTRIES # from pygal.maps.world import COUNTRIES # from pygal_maps_world import i18n for country_code in COUNTRIES.keys(): print(country_code, COUNTRIES[country_code])
import pygal from pygal_maps_world.i18n import COUNTRIES for code in COUNTRIES.keys(): print(code, COUNTRIES[code]) def get_code(country_name): for code, name in COUNTRIES.items(): if name == country_name: return code return None
from pygal_maps_world.i18n import COUNTRIES import json # def get_country_code(country_name): # """Return the Pygal 2-digit country code for the given country.""" # for code, name in COUNTRIES.items(): # if name == country_name: # return code # # If the country wasn't found, return None. # return None # filename = 'population_data.json' # with open(filename) as f: # pop_data = json.load(f) for country in sorted(COUNTRIES.keys()): print(COUNTRIES[country]) # for country_code in sorted(COUNTRIES.keys()): # print(country_code, COUNTRIES[country_code]) for items