推荐一款命令行随机数据生成工具

shigen坚持更新文章的博客写手,擅长Java、python、vue、shell等编程语言和各种应用程序、脚本的开发。记录成长,分享认知,留住感动。 个人IP:shigen

shigen之前的文章如何用python优雅的生成模拟数据[1]中,采用了faker这个库实现了随机数据的生成。但是有点小傻,因为我今天发现我的本地安装了conda环境,自带了faker,可以直接在命令行使用:

推荐一款命令行随机数据生成工具
conda自带的faker

那既然这样的话,研究一下命令行的使用吧。官方给了具体的案例,具体可通过faker --help来查看,或者访问faker的官方文档[2]

When installed, you can invoke faker from the command-line:

faker [-h] [--version] [-o output]
      [-{bg_BG,cs_CZ,...,zh_CN,zh_TW}]
      [-r REPEAT] [-s SEP]
      [-{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: shows a help message

--version: shows the programs version number

-o FILENAME: redirects the output to the specified filename

-{bg_BG,cs_CZ,...,zh_CN,zh_TW}: allows use of a localized provider

-r REPEAT: will generate a specified number of outputs

-s SEP: will generate the specified separator after each generated output

-{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: is the name of the fake to generate an output for, such as name, address, or text

[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)

接下来就是一些我的实际测试。

模拟地址

faker address                                                                                                                                            
辽宁省雪市六枝特沈阳街P 502847

模拟ipv4

faker ipv4                                                                                                                                                          
160.100.231.46

模拟user_agent

faker user_agent
Mozilla/5.0 (X11; Linux i686; rv:1.9.7.20) Gecko/2012-11-11 14:57:49 Firefox/5.0

当然,能随机生成的还有很多,我们基本可以按照官方给的文档来:

推荐一款命令行随机数据生成工具
支持生成的随机数据类型

那接下来展示高级的:

生成指定数量指定分隔符的数据

faker -10 -';' name                                                                                                                                  
韩秀华;
贺超;
顾桂荣;
田萍;
刘颖;
朱洋;
吴玲;
韩磊;
谭想;
康浩;

生成json数据

faker -10 -';' profile name,ipv4,address,company                                                                                                     
{'company': '南康传媒有限公司', 'name': '李璐', 'address': '北京市惠州县新城郭路W座 769810'};

生成json数据并保存在文件

推荐一款命令行随机数据生成工具
生成的数据保存在文件中

以上就是关于faker这个命令行工具的分享,期待用它提升实际的效率,也欢迎伙伴们的交流分享。

与shigen一起,每天不一样!

引用链接

[1] 如何用python优雅的生成模拟数据: https://juejin.cn/post/7263886796757794876
[2] faker的官方文档: https://faker.readthedocs.io/en/master/


原文始发于微信公众号(shigen):推荐一款命令行随机数据生成工具

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/266970.html

(0)
服务端技术精选的头像服务端技术精选

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!