从Faker获取受支持国家列表

问题描述 投票:-1回答:1

下面是一个示例脚本,可帮助我在指定国家/地区内生成经纬度。

如何从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')
python faker
1个回答
0
投票

感谢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]
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.