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

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

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

conda自带的faker

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

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

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: shows a help message

--version: shows the program’s version number

-o FILENAME: redirects the output to the specified filename

-l {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

-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: 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 -r 10 -s ';' name                                                                                                                                  
韩秀华;
贺超;
顾桂荣;
田萍;
刘颖;
朱洋;
吴玲;
韩磊;
谭想;
康浩;

生成json数据

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

生成json数据并保存在文件

生成的数据保存在文件中

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

与shigen一起,每天不一样!

  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值