【发布时间】:2017-11-16 01:48:03
【问题描述】:
我使用从this question 获得的以下代码从他们的俄罗斯名称中获取国家代码。
def get_country_code(russian_name):
gettext.translation('iso3166', pycountry.LOCALES_DIR, languages=['RU']).install()
country_code = ''.join([country.alpha_2 for country in pycountry.countries if _(country.name) == russian_name])
return country_code
但是当我尝试在我的 jupyter-notebook 中使用这个功能时,它给了我以下错误:
TypeError: 'str' object is not callable
这似乎是因为在 jupyter 以及交互模式下 _ 表示先前计算的结果,但 gettext 将其定义为它的函数。
如何在 Jupyter 中执行此代码?
【问题讨论】:
标签: python ipython jupyter-notebook jupyter gettext