下面是一个示例脚本,可帮助我在指定国家/地区内生成经纬度。
如何从Faker获取可以作为country_code属性传递的受支持的语言环境列表?
## https://faker.readthedocs.io/en/master/index.html#localization
## !pip install Faker
from faker import Faker
fake = Faker()
fake.local_latlng(country_code='GB', coords_only=False)
>('50.82882', '-0.32247', 'Lancing', 'GB', 'Europe/London')
感谢user1558604
from faker.config import AVAILABLE_LOCALES
def getLocale (lc):
loc = lc.split('_')
if len(loc)>1:
return loc[1].upper()
else:
return loc[0].upper()
[fake.local_latlng(country_code=getLocale(local), coords_only=False) for local in AVAILABLE_LOCALES]