简体   繁体   中英

Using Below Code i m able to find states present in a country, is There any method to find cities within the given states using python

提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供   中文简体   中文繁体   中英对照 版本,有任何建议请联系yoyou2525@163.com。

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"])
1 anwsers

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

暂无
暂无

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2022 STACKOOM.COM