我知道使用 python 脚本生成机场数据,例如:
python -c "from faker import Faker; from faker_airtravel import AirTravelProvider; fake = Faker(); fake.add_provider(AirTravelProvider); airports = [fake.airport_name() for _ in range(10)]; print(airports)"
这会按预期返回数据:
['卡胡卢伊机场', '太原武宿机场', '卡里尔苏尔国际机场', '福冈机场', '古斯塔维亚机场', '圣玛丽亚机场', '萨尔塔机场', '塔科马国际机场', '卡米洛·达萨机场', '尼洛·科埃略参议员机场']
但是我正在努力如何通过 faker -i 命令行选项在没有 python 的情况下使用 faker 生成相同的内容:
$ faker -i faker_airtravel airport_name
AttributeError: module 'faker_airtravel' has no attribute 'Provider'
$ faker -i faker_airtravel.AirTravelProvider airport_name
ModuleNotFoundError: No module named 'faker_airtravel.AirTravelProvider'
$ faker -i AirTravelProvider airport_name
ModuleNotFoundError: No module named 'AirTravelProvider'
Google 只返回 python 示例,无法找到使用 -i 执行 faker 来添加社区提供商的命令行示例 - 就像安装的 faker_airtravel 一样:
$ pip install faker_airtravel
发出
faker -h
显示选项 -i 来加载额外的提供程序,但我很难理解如何让它工作:
faker -h
usage: faker [-h] [--version] [-v] [-o output] [-l LOCALE] [-r REPEAT] [-s SEP] [--seed SEED] [-i [INCLUDE ...]] [fake] [fake argument ...]
faker version 18.9.0
positional arguments:
fake name of the fake to generate output for (e.g. profile)
fake argument optional arguments to pass to the fake (e.g. the profile fake takes an optional list of comma separated field names as the first argument)
options:
-h, --help show this help message and exit
--version show program's version number and exit
-v, --verbose show INFO logging events instead of CRITICAL, which is the default. These logging events provide insight into localization of specific providers.
-o output redirect output to a file
-l LOCALE, --lang LOCALE
specify the language for a localized provider (e.g. de_DE)
-r REPEAT, --repeat REPEAT
generate the specified number of outputs
-s SEP, --sep SEP use the specified separator after each output
--seed SEED specify a seed for the random generator so that results are repeatable. Also compatible with 'repeat' option
-i [INCLUDE ...], --include [INCLUDE ...]
list of additional custom providers to user, given as the import path of the module containing your Provider class (not the provider class itself)
我很想看看从提供商处生成 10 个 airport_name 需要什么命令行
$ pip install faker_airtravel
我想知道问题是否在于获取命令行语法或正确的命名空间,或者是否与如何正确安装提供程序有关......也许更需要而不是简单:
$ pip install faker_airtravel
我怀疑我的疑问有简单的答案😲😁