如何以编程方式列出Faker生成器对象中的所有可用方法?

Faker文档显示了如何创建faker生成器并生成数据:

from faker import Faker

fake = Faker()

fake.name()

# 'Lucy Cechtelar'

fake.address()

# '426 Jordy Lodge

# Cartwrightshire, SC 88120-6700'

我希望这些方法name和address在上市展现出来fake的对象,但没有运气:

dir(fake)

# ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattr__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_factories', '_factory_map', '_locales', '_map_provider_method', '_select_factory', '_weights', 'cache_pattern', 'factories', 'generator_attrs', 'items', 'locales', 'random', 'seed', 'seed_instance', 'seed_locale', 'weights']

有没有一种方法可以创建可在faker生成器上调用的所有方法的列表?

编辑2020年8月3日:

他们终于在4.0.3版中添加了此功能,现在可以使用了:

为Faker代理实现了dir方法,以实现更好的自动完成。谢谢@douglasfarinelli。

解决方案

您可以尝试以下方法:

>>> from faker import Faker

>>> F = Faker()

>>> dir(F)

我有很多方法:

[... 'add_provider', 'address', 'am_pm', 'android_platform_token', 'ascii_company_email', 'ascii_email', 'ascii_free_email', 'ascii_safe_email', 'bank_country', 'bban', 'binary', 'boolean', 'bothify', 'bs', 'building_number', 'cache_pattern', 'catch_phrase', 'century', 'chrome', 'city', 'city_prefix', 'city_suffix', 'color', 'color_name', 'company', 'company_email', 'company_suffix', 'coordinate', 'country', 'country_calling_code', 'country_code', 'credit_card_expire', 'credit_card_full', 'credit_card_number', 'credit_card_provider', 'credit_card_security_code', 'cryptocurrency', 'cryptocurrency_code', 'cryptocurrency_name', 'csv', 'currency', 'currency_code', 'currency_name', 'currency_symbol', 'date', 'date_between', 'date_between_dates', 'date_object', 'date_of_birth', 'date_this_century', 'date_this_decade', 'date_this_month', 'date_this_year', 'date_time', 'date_time_ad', 'date_time_between', 'date_time_between_dates', 'date_time_this_century', 'date_time_this_decade', 'date_time_this_month', 'date_time_this_year', 'day_of_month', 'day_of_week', 'dga', 'domain_name', 'domain_word', 'dsv', 'ean', 'ean13', 'ean8', 'ein', 'email', 'factories', 'file_extension', 'file_name', 'file_path', 'firefox', 'first_name', 'first_name_female', 'first_name_male', 'format', 'free_email', 'free_email_domain', 'future_date', 'future_datetime', 'generator_attrs', 'get_formatter', 'get_providers', 'hex_color', 'hexify', 'hostname', 'http_method', 'iban', 'image_url', 'internet_explorer', 'invalid_ssn', 'ios_platform_token', 'ipv4', 'ipv4_network_class', 'ipv4_private', 'ipv4_public', 'ipv6', 'isbn10', 'isbn13', 'iso8601', 'items', 'itin', 'job', 'language_code', 'language_name', 'last_name', 'last_name_female', 'last_name_male', 'latitude', 'latlng', 'lexify', 'license_plate', 'linux_platform_token', 'linux_processor', 'local_latlng', 'locale', 'locales', 'localized_ean', 'localized_ean13', 'localized_ean8', 'location_on_land', 'longitude', 'mac_address', 'mac_platform_token', 'mac_processor', 'md5', 'military_apo', 'military_dpo', 'military_ship', 'military_state', 'mime_type', 'month', 'month_name', 'msisdn', 'name', 'name_female', 'name_male', 'null_boolean', 'numerify', 'opera', 'paragraph', 'paragraphs', 'parse', 'password', 'past_date', 'past_datetime', 'phone_number', 'port_number', 'postalcode', 'postalcode_in_state', 'postalcode_plus4', 'postcode', 'postcode_in_state', 'prefix', 'prefix_female', 'prefix_male', 'profile', 'provider', 'providers', 'psv', 'pybool', 'pydecimal', 'pydict', 'pyfloat', 'pyint', 'pyiterable', 'pylist', 'pyset', 'pystr', 'pystr_format', 'pystruct', 'pytimezone', 'pytuple', 'random', 'random_choices', 'random_digit', 'random_digit_not_null', 'random_digit_not_null_or_empty', 'random_digit_or_empty', 'random_element', 'random_elements', 'random_int', 'random_letter', 'random_letters', 'random_lowercase_letter', 'random_number', 'random_sample', 'random_uppercase_letter', 'randomize_nb_elements', 'rgb_color', 'rgb_css_color', 'safari', 'safe_color_name', 'safe_email', 'safe_hex_color', 'secondary_address', 'seed', 'seed_instance', 'seed_locale', 'sentence', 'sentences', 'set_formatter', 'sha1', 'sha256', 'simple_profile', 'slug', 'ssn', 'state', 'state_abbr', 'street_address', 'street_name', 'street_suffix', 'suffix', 'suffix_female', 'suffix_male', 'tar', 'text', 'texts', 'time', 'time_delta', 'time_object', 'time_series', 'timezone', 'tld', 'tsv', 'unix_device', 'unix_partition', 'unix_time', 'upc_a', 'upc_e', 'uri', 'uri_extension', 'uri_page', 'uri_path', 'url', 'user_agent', 'user_name', 'uuid4', 'weights', 'windows_platform_token', 'word', 'words', 'year', 'zip', 'zipcode', 'zipcode_in_state', 'zipcode_plus4']

python列出所有方法_如何在python中列出所有Faker方法相关推荐

  1. python指定返回类型_如何在python中指定方法返回类型列表 - python

    假设我有一个类似下面的方法 def validate(self, item:dict, attrs:dict)-> list: 如果我想更具体一点,告诉我我的返回类型是 验证消息? 我应该如何实 ...

  2. python队列怎么用_如何在Python中使用多处理队列? - python

    我很难理解多处理队列如何在python上工作以及如何实现它.假设我有两个python模块,它们从共享文件中访问数据,我们将这两个模块称为writer和Reader.我的计划是让读取器和写入器都将请求放 ...

  3. python字符串筛选输出_如何在Python中过滤字符串列表

    Python使用列表数据类型在顺序索引中存储多个数据.它的工作方式类似于其他编程语言的数字数组.filter()方法是Python的一种非常有用的方法.可以使用filter()方法从Python中的任 ...

  4. python隐藏启动台_如何在Python中启动后台进程?

    如何在Python中启动后台进程? 我正在尝试将shell脚本移植到更易读的python版本. 原始shell脚本在后台使用"&"启动多个进程(实用程序,监视器等). 如何 ...

  5. python绘图背景透明_如何在 Matplotlib 中更改绘图背景

    介绍Matplotlib是Python中使用最广泛的数据可视化库之一.无论是简单还是复杂的可视化项目,它都是大多数人的首选库.在本教程中,我们将研究如何在Matplotlib中更改绘图的背景.导入数据 ...

  6. python获取当前时间戳_如何在Python中获取当前时间戳?

    在Python中可以使用来自模块time.datetime或calendar的函数来获取当前时间戳,代码语句如[import time;ts = time.time() print(ts)]. 在Py ...

  7. python静态变量计数器_如何在Python中使用静态变量在计数

    今天,在用Python写一个统计一个文件下有多少文件的小标本时,遇到了一个很棘手的问题.如何在Python中使用静态变量来计数.然后,就在网上一通查找,找的方法都是利用类的方法来实现静态变量.说实话没 ...

  8. python的loc函数_如何在pandas中使用loc、iloc函数进行数据索引(入门篇)

    在数据分析过程中,很多时候我们需要从数据表中提取出我们需要的部分,而这么做的前提是我们需要先索引出这一部分数据.今天我们就来探索一下,如何在pandas中使用loc函数和iloc函数索引数据. 今天我 ...

  9. python列表元素求和_如何在python语言使用不同方法实现列表元素求和

    在使用python语言列表时,如果列表中的元素都是数值类型,可以对元素进行求和.下面利用不同的方法实现列表元素求和: 工具/原料 python pycharm 截图工具 方法/步骤 1 第一步,在已创 ...

最新文章

  1. 刺客信条奥德赛无法加载库_点评刺客信条起源、奥德赛、英灵殿,哪个最好玩?...
  2. python3 报错 TypeError: load() got an unexpected keyword argument ‘encoding‘ 解决方法
  3. java 编写命令行工具_编写命令行工具
  4. 用TensorFlow和TensorBoard从零开始构建ConvNet(CNN)
  5. [摘录]第五章 与奋斗者分享利益
  6. 请在贵网站的根目录下部署一个文件_使用 github pages, 快速部署你的静态网页
  7. 二进制全排列 java_排列组合算法真厉害,傻瓜都能学会
  8. rabbitmq-路由模式-routingkey
  9. jqgrid demo java_java – jqgrid如何显示服务器端消息
  10. c语言链表实践报告,双向链表的实践(C语言)
  11. JavaWeb-10(会话技术之sessionamp;JSP)
  12. Java编程:排序算法——快速排序
  13. php redis令牌桶,php 基于redis使用令牌桶算法实现流量控制
  14. 03、ADS使用记录之DC仿真控制器的使用
  15. c语言写街机,C 实现 Atari 经典街机游戏《飞天蜈蚣》
  16. Jenkins-cents7.6 rpm安装
  17. 固态硬盘与机械硬盘的区别
  18. 用C语言实现base64解密(包括二进制文件)
  19. 崖山数据库系统YashanDB荣获“2022年度信创卓越贡献奖”
  20. TiDB监控pd面板显示:Region Health: empty-regin-count很多,怎么回收empty-regin?

热门文章

  1. 怎么才能做同声传译?利用好这些软件就可以实现
  2. 骆俊武:编程高手是如何练成的?
  3. 用python编写Djikstra算法进行机器人路径规划
  4. 影视作品制作中不可或缺的技术支撑——云渲染技术
  5. Linux如何杀死全部进程,Linux 杀死所有进程
  6. 浙大 c语言文件详解 格式化输入输出详解 打开文件
  7. MapReduce 数据倾斜以及解决思路
  8. 仙剑缘_仙剑缘手游最新单机版客户端下载-仙剑缘单机版v1.3.2 安卓版-腾牛安卓网...
  9. asp.net 简体字转繁体字的类库
  10. 金融数据挖掘Jupyter—北京市二手房数据分析—课设