-1

Using this code I am able to find states of country I want to find all cities within given state, suppose I enter the state name I get all cities within that state:

from countryinfo import CountryInfo
name = "India"
country = CountryInfo(name)
data = country.info()
print(data["provinces"])
Sunderam Dubey
  • 1
  • 11
  • 20
  • 40

1 Answers1

0

Try using Python's built-in dir(theobject) method to inspect CountryInfo object like so:

dir(CountryInfo)

In order to list all the fields and methods of your object (as a tuple) and the inspect module (as codeape write) to list the fields and methods within the doc. Or use help(object) to get details of the object whether there exist a method for finding cities given a state.

From the results, you will be able to know if you can get your cities or not from the countryinfo module.

I saw a resource about this module here: https://medium.com/analytics-vidhya/fetch-all-information-of-any-country-using-python-baa72a669d68 However, it only gives you the capital city for a given country.

data2 = country.capital()

print(data2)

#Output:

New Delhi

You might need a different python module.

Checkout Retrieve cities list of a country