是否可以从 pycountry 1.15 中获取所有 ISO639-1 语言代码的列表?例如,['en','it','el','fr',...]?如果是那么怎么办?
恐怕以下内容不起作用:
import pycountry
pycountry.languages
最佳答案
这将为您提供两位 ISO3166-1 国家/地区代码列表:
countries = [country.alpha2 for country in pycountry.countries]
#countries = [country.alpha_2 for country in pycountry.countries] # for python3
这将为您提供两位 ISO639-1 语言代码的列表:
langs = [lang.iso639_1_code
for lang in pycountry.languages
if hasattr(lang, 'iso639_1_code')]
这将为您提供所有语言代码的列表:
langs = [getattr(lang, 'iso639_1_code', None) or
getattr(lang, 'iso639_2T_code', None) or
getattr(lang, 'iso639_3_code')
for lang in pycountry.languages]
关于python - Python 中的语言代码列表(ISO639-1)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32773035/