0
votes

I try to get the country id when I give the country's name.

import pycountry

pays = "france"

initales_pays = pycountry.countries.search_fuzzy(pays)
print(initales_pays)

And the result is

[Country(alpha_2='FR', alpha_3='FRA', name='France', numeric='250', official_name='French Republic')]

How can I take the alpha_2?

1
What did you find in the documentation of pycountry about this?mkrieger1
i didn't find my answer in the pycountry doc :s , i found that "germany = pycountry.countries.get(alpha_2='DE')" but that doesnt compileguiguilecodeur

1 Answers

2
votes

According to the examples shown on the pycountry page on PyPI, the properties of a Country instance can be accessed as attributes.

In your case this would be:

country = initales_pays[0]
country.alpha_2  # 'FR'