我知道按照下面的方法我可以得到woocommerce中的国家: 或者 但我想知道如何找到任何国家的州/城市。 ...
提示:本站收集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:使用此代码,我可以找到我想查找给定 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.