pycountry icon indicating copy to clipboard operation
pycountry copied to clipboard

pycountry.subdivisions.get(name='British Columbia') is not getting the value

Open rholloway4 opened this issue 4 years ago • 1 comments

Trying to use this to get name, but saying KeyError, not sure why since in your steps states to input "code, name, or type"....

exact quote "Subdivisions can be accessed using their unique code and provide at least their code, name and type:"

Traceback (most recent call last): File "", line 1, in File "C:\Users\rhollow\Python37-32\lib\site-packages\pycountry_init_.py", line 189, in get subdivisions = super(Subdivisions, self).get(**kw) File "C:\Users\rhollow\Python37-32\lib\site-packages\pycountry\db.py", line 41, in load_if_needed return f(self, *args, **kw) File "C:\Users\rhollow\Python37-32\lib\site-packages\pycountry\db.py", line 113, in get index = self.indices[field] KeyError: 'name'

rholloway4 avatar Dec 20 '21 18:12 rholloway4

Duplicate of #66

It seems you can use: pycountry.subdivisions.lookup('British Columbia')

Paul-DS avatar Feb 23 '22 16:02 Paul-DS

@rholloway4 the language

Subdivisions can be accessed using their unique code and provide at least their code, name and type:

Indicates that the subdivisions can be accessed using their unique code... doing so will provide at least their code, name and type. I agree the language is a bit confusing. @Paul-DS is correct that the way to search by name is using lookup.

Going to make a quick update the README

nschimmoller avatar Dec 08 '23 20:12 nschimmoller