简体   繁体   English

使用下面的代码我能够找到一个国家存在的州,是否有任何方法可以使用 python 找到给定州内的城市

[英]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

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:使用此代码,我可以找到我想查找给定 state 内的所有城市的国家/地区,假设我输入 state 名称,我得到该 state 内的所有城市:

from countryinfo import CountryInfo
name = "India"
country = CountryInfo(name)
data = country.info()
print(data["provinces"])

Try using Python's built-in dir(theobject) method to inspect CountryInfo object like so:尝试使用 Python 的内置dir(theobject)方法来检查 CountryInfo object,如下所示:

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.为了列出 object(作为元组)和检查模块(作为 codeape 写入)的所有字段和方法,以列出文档中的字段和方法。 Or use help(object) to get details of the object whether there exist a method for finding cities given a state.或者使用 help(object) 获取 object 的详细信息,是否存在给定 state 的查找城市的方法。

From the results, you will be able to know if you can get your cities or not from the countryinfo module.从结果中,您将能够知道是否可以从 countryinfo 模块中获取您的城市。

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.我在这里看到了有关此模块的资源: https://medium.com/analytics-vidhya/fetch-all-information-of-any-country-using-python-baa72a669d68但是,它只为您提供给定的首都城市国家。

data2 = country.capital()数据2 =国家.资本()

print(data2)打印(数据2)

#Output: #输出:

New Delhi新德里

You might need a different python module.您可能需要不同的 python 模块。

Checkout Retrieve cities list of a country结帐检索一个国家的城市列表

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在使用 python 国家图书馆,并希望使用 python 列出和打印给定国家的总州和城市是否可以做到 - I m Using python countries library and want to list and print total states and cities of given country using python is it possible to do it 我正在使用 windows7 和 Pycharm 2019.3 和 Python 3,在下面的代码中找不到 cvtColor 命令的解决方案: - I'm using windows7 and Pycharm 2019.3 with Python 3, Can't find the solution to cvtColor command in the code below: Python获取城市,州,地区的列表 - Python get a list of cities, states, region 我想比较两个城市的列表,如果列表 B 的城市不在列表 A 中,那么列表 A 中的 append 应该使用 python - I want to compare list of two cities and if list B cities are not present in list A then should append in list A using python 当我 select 一个特定国家/地区时,我有一个国家和州的 df 我需要获得 output 如下 - I have a df with countries and states when I select a particular country I need to get the output as below Python Geoip使用JSON查找国家 - Python geoip find country using json 如何实现最短路径算法来查找python中任意两个给定城市之间的最短路径? - How to implement a shortest path algorithm to find shortest route between any two given cities of a graph in python? Python Selenium 给定一个元素,使用 element.find_element 在直接子项下查找元素 - Python Selenium given an element, find elements below direct children using element.find_element 如何使用旅行时间矩阵在给定旅行预算(以分钟为单位)的情况下找到我可以访问的最大城市数 - How can I find the maximum number of cities that I can visit given a travel budget (in minutes) using a travel time matrix 我想使用 python 从数字之间删除加法符号,请在下面找到我的代码 - I want to Remove the addition symbol from in-between the numbers using python and please find the below my code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM