读书笔记《Python编程从入门到实践》P327

在学习时,我们发现代码

from pygal.i18n import COUNTRIES

for country_code in sorted(COUNTRIES.keys()):
    print(country_code, COUNTRIES[country_code])


运行报错

原因是
COUNTRIES已经不在pygal.i18n模块里了,而是在pygal.maps.world模块里
用命令行 pip install pygal_maps_world
再修改一下代码

from pygal.maps.world import COUNTRIES
for country_code in sorted(COUNTRIES.keys()):
    print(country_code, COUNTRIES[country_code])

结果:

读书笔记《Python编程从入门到实践》P327_第1张图片

没毛病
ok!

还没完

在运行代码

wm = pygal.Worldmap()

又出错了!
再修改一下下

wm = pygal.maps.world.World()

就行了
要注意的是 在现在的 pygal 里面 maps 原有的功能被划分到了 maps.world里面

你可能感兴趣的:(读书笔记《Python编程从入门到实践》P327)