4000-520-616
欢迎来到免疫在线!(蚂蚁淘生物旗下平台)  请登录 |  免费注册 |  询价篮
主营:原厂直采,平行进口,授权代理(蚂蚁淘为您服务)
咨询热线电话
4000-520-616
当前位置: 首页 > 新闻动态 >
新闻详情
Python使用FaKer模拟数据!!!_追心-CSDN博客
来自 : CSDN技术社区 发布时间:2021-03-24

hello 小伙伴们 大家好 今天给大家介绍的开源项目是: Faker 它解决的问题是python模拟 随机 数据 不知道大家在工作中没有用到过假数据 特别前后端开发的人员 应该经常用到 前端人员页面展示 效果展示。后端人员数据库数据模拟。今天给大家介绍的这个项目完美的解决了这个方案 可以模拟多种语言的数据 中文 英文 日语 韩语等等。有兴趣的小伙伴可以下载尝试一下。

_|_|_|_| _|_| _|_|_| _| _| _|_| _| _|_|_|_|_| _| _| _|_| _|_|_|_| _|_|_| _| _| _| _| _| _|_| _|_|_| _| _| _|_|_| _|
安装
pip install Faker
基本用法

使用faker.Faker()初始化 可通过访问你想要的数据类型来命名的属性生成你要的数据。

from faker import Fakerfake Faker()fake.name()# Lucy Cechtelar fake.address()# 426 Jordy Lodge# Cartwrightshire, SC 88120-6700 fake.text()# Sint velit eveniet. Rerum atque repellat voluptatem quia rerum. Numquam excepturi# beatae sint laudantium consequatur. Magni occaecati itaque sint et sit tempore. Nesciunt# amet quidem. Iusto deleniti cum autem ad quia aperiam.# A consectetur quos aliquam. In iste aliquid et aut similique suscipit. Consequatur qui# quaerat iste minus hic expedita. Consequuntur error magni et laboriosam. Aut aspernatur# voluptatem sit aliquam. Dolores voluptatum est.# Aut molestias et maxime. Fugit autem facilis quos vero. Eius quibusdam possimus est.# Ea quaerat et quisquam. Deleniti sunt quam. Adipisci consequatur id in occaecati.# Et sint et. Ut ducimus quod nemo ab voluptatum. 

每次对方法的调用都会fake.name()产生不同的 随机 结果。这是因为造假者将faker.Generator.method_name()呼叫转发给faker.Generator.format(method_name)。

from faker import Fakerfake Faker( zh-CN )fake.name()# 张柳 fake.address()# 黑龙江省辽阳县江北李路C座 461467 fake.text()# 继续浏览音乐行业国内什么.任何同时专业但是人民而且无法.认为大家的是更新.数据设备日本更多.生活发表一般最大一下.状态得到游戏今天喜欢.专业无法工作这么文化如此感觉教育.工程全部详细注意.现在增加女人一些日本觉得不过.感觉原因全部感觉表示.质量所以管理但是因此.图片都是一种注册表示主要汽车影响.质量喜欢有关希望更多.已经那个更多决定运行.系列名称完全研究女人没有企业. 

可以自定义不同的语言 也可以输出多种语言 这里我们就展示中英文 有兴趣的可以去查看官方文档。

生成IP地址
from faker import Fakerfrom faker.providers import internetfake Faker()fake.add_provider(internet)print(fake.ipv4_private())# 192.168.91.234 

随机生成IP地址 每次产生不同的 随机 结果。

命令行用法
faker [-h] [--version] [-o output] [-l {bg_BG,cs_CZ,...,zh_CN,zh_TW}] [-r REPEAT] [-s SEP] [-i {package.containing.custom_provider otherpkg.containing.custom_provider}] [fake] [fake argument [fake argument ...]]

Where:

faker: is the script when installed in your environment, in development you could use python -m faker instead-h, --help: 显示帮助文档--version: 显示版本信息-o FILENAME: 将输出重定向到指定的文件名中。-l {bg_BG,cs_CZ,...,zh_CN,zh_TW}: 允许自定义语言 一种或多种语言。-r REPEAT: 指定输出的数量-s SEP: 每次生成输出后 会生成指定的字符-i {my.custom_provider other.custom_provider} list of additional custom providers to use. Note that is the import path of the package containing your Provider class, not the custom Provider class itself.fake: 用于生成输出(例如名称、地址或文本)的伪名称[fake argument ...]: 传递给fake的可选参数
$ faker address968 Bahringer Garden Apt. 722Kristinaland, NJ 09890$ faker -l de_DE addressSamira-Niemeier-Allee 5694812 Biedenkopf$ faker profile ssn,birthdate{ ssn : u 628-10-1085 , birthdate : 2008-03-29 }$ faker -r 3 -s nameWillam Kertzmann;Josiah Maggio;Gayla Schmitt;
自定义数据

如果不想使用默认数据 可以提供自己的单词集。

fake Faker()my_word_list [ danish , cheesecake , sugar , Lollipop , wafer , Gummies , sesame , Jelly , beans , pie , bar , Ice , oat ]fake.sentence()# Expedita at beatae voluptatibus nulla omnis. fake.sentence(ext_word_list my_word_list)# Oat beans oat Lollipop bar cheesecake. 
常用例子
from faker import Fakerfrom faker.providers import internetfake Faker( zh-CN )# 产生随机手机号print(fake.phone_number())# 产生随机姓名print(fake.name())# 产生随机地址print(fake.address())# 随机产生国家名print(fake.country())# 随机产生国家代码print(fake.country_code())# 随机产生城市名print(fake.city_name())# 随机产生城市print(fake.city())# 随机产生省份print(fake.province())# 产生随机emailprint(fake.email())# 产生随机IPV4地址print(fake.ipv4())# 产生长度在最大值与最小值之间的随机字符串print(fake.pystr(min_chars 0, max_chars 8))# 随机产生车牌号print(fake.license_plate())# 随机产生颜色print(fake.rgb_color()) # rgbprint(fake.safe_hex_color()) # 16进制print(fake.color_name()) # 颜色名字print(fake.hex_color()) # 16进制# 随机产生公司名print(fake.company())# 随机产生工作岗位print(fake.job())# 随机生成密码print(fake.password(length 10, special_chars True, digits True, upper_case True, lower_case True))# 随机生成uuidprint(fake.uuid4())# 随机生成sha1print(fake.sha1(raw_output False))# 随机生成md5print(fake.md5(raw_output False))# 随机生成女性名字print(fake.name_female())# 男性名字print(fake.name_male())# 随机生成名字print(fake.name())# 生成基本信息print(fake.profile(fields None, sex None))print(fake.simple_profile(sex None))# 随机生成浏览器头user_agentprint(fake.user_agent())# 随机产生时间 月份print(fake.month_name())# May print(fake.date_time_this_century(before_now True, after_now False, tzinfo None))# 2005-10-08 08:32:02print(fake.time_object(end_datetime None))# 06:45:11print(fake.date_time_between(start_date -10y , end_date now , tzinfo None))# 2012-08-25 03:07:38print(fake.future_date(end_date 30d , tzinfo None))# 2020-04-25print(fake.date_time(tzinfo None, end_datetime None))# 2002-09-01 18:27:45print(fake.date(pattern %Y-%m-%d , end_datetime None))# 1998-08-02 print(fake.date_time_this_month(before_now True, after_now False, tzinfo None))# 2020-04-03 16:03:21print(fake.timezone())# Africa/Addis_Ababa print(fake.date_time_this_decade(before_now True, after_now False, tzinfo None))# 2020-01-09 01:15:08print(fake.month())# 04 print(fake.day_of_week())# Sunday print(fake.iso8601(tzinfo None, end_datetime None))# 1988-02-28T09:22:29 print(fake.date_object(end_datetime None))# 2017-06-26print(fake.date_this_decade(before_today True, after_today False))# 2020-03-30fake.date_this_century(before_today True, after_today False)# datetime.date(2000, 6, 1)fake.date_this_month(before_today True, after_today False)# datetime.date(2018, 6, 13)fake.am_pm()# AM fake.past_datetime(start_date -30d , tzinfo None)# datetime.datetime(2018, 6, 25, 7, 41, 34)fake.date_this_year(before_today True, after_today False)# datetime.date(2018, 2, 24)fake.date_time_between_dates(datetime_start None, datetime_end None, tzinfo None)# datetime.datetime(2018, 6, 26, 14, 40, 5)fake.date_time_ad(tzinfo None, end_datetime None)# datetime.datetime(673, 1, 28, 18, 17, 55)fake.date_between_dates(date_start None, date_end None)# datetime.date(2018, 6, 26)fake.future_datetime(end_date 30d , tzinfo None)# datetime.datetime(2018, 7, 4, 10, 53, 6)fake.century()# IX fake.past_date(start_date -30d , tzinfo None)# datetime.date(2018, 5, 30)fake.time(pattern %H:%M:%S , end_datetime None)# 01:32:14 fake.day_of_month()# 19 fake.unix_time(end_datetime None, start_datetime None)fake.date_time_this_year(before_now True, after_now False, tzinfo None)# datetime.datetime(2018, 5, 24, 11, 25, 25)fake.date_between(start_date -30y , end_date today )# datetime.date(2003, 1, 11)fake.year()# 1993 fake.time_series(start_date -30d , end_date now , precision None, distrib None, tzinfo None)# generator object time_series at 0x7f44e702a620 # 随机产生文件fake.file_extension(category None)# xls print(fake.file_name(category None, extension None))# 那么.movfake.file_path(depth 1, category None, extension None)# /教育/客户.js fake.unix_device(prefix None)# /dev/sdf print(fake.unix_partition(prefix None))# /dev/vdv4 print(fake.mime_type(category None))# message/imdn xml 

开源地址: https://github.com/joke2k/fakerv
项目文档 https://faker.readthedocs.io/en/master/

今天的推荐不知道大家喜欢吗 如果你们喜欢话 请在文章底部留言或点赞 以表示对我的支持 你们的留言 点赞 转发关注是我持续更新的动力哦

关注公众号回复 1024 免费领取一大波学习资源 先到先得哦

\"关注我免费领取学习资料\"

本文链接: http://fakeprint.immuno-online.com/view-696763.html

发布于 : 2021-03-24 阅读(0)
公司介绍
联络我们
服务热线:4000-520-616
(限工作日9:00-18:00)
QQ :1570468124
手机:18915418616
官网:http://