Table of Contents
20 Jan 2023
Library resources | |
---|---|
PyPI | https://pypi.org/project/pycountry/ |
Github | https://github.com/flyingcircusio/pycountry |
Documentation | --- |
Getting Started
pip install pycountry
Usage
import pycountry
def get_country_code(location):
try:
country = pycountry.countries.search_fuzzy(location)
return country[0].alpha_2
except:
return None
Returns a LookupError: cambridge, massachusetts
when doing a fuzzy search with "Cambridge, Massachusetts" as input.
Trying geopy now Python Library: geopy