前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >推荐一款命令行随机数据生成工具

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

原创
作者头像
shigen
发布2024-04-02 16:54:29
900
发布2024-04-02 16:54:29
举报

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

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

conda自带的faker
conda自带的faker

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

代码语言:shell
复制
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)

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

模拟地址

代码语言:shell
复制
faker address                                                                                                                                            
辽宁省雪市六枝特沈阳街P座 502847

模拟ipv4

代码语言:shell
复制
faker ipv4                                                                                                                                                          
160.100.231.46

模拟user_agent

代码语言:shell
复制
faker user_agent
Mozilla/5.0 (X11; Linux i686; rv:1.9.7.20) Gecko/2012-11-11 14:57:49 Firefox/5.0

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

支持生成的随机数据类型
支持生成的随机数据类型

那接下来展示高级的:

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

代码语言:shell
复制
faker -r 10 -s ';' name                                                                                                                                  
韩秀华;
贺超;
顾桂荣;
田萍;
刘颖;
朱洋;
吴玲;
韩磊;
谭想;
康浩;

生成json数据

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

生成json数据并保存在文件

生成的数据保存在文件中
生成的数据保存在文件中

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

与shigen一起,每天不一样!

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 模拟地址
  • 模拟ipv4
  • 模拟user_agent
  • 生成指定数量指定分隔符的数据
  • 生成json数据
  • 生成json数据并保存在文件
相关产品与服务
命令行工具
腾讯云命令行工具 TCCLI 是管理腾讯云资源的统一工具。使用腾讯云命令行工具,您可以快速调用腾讯云 API 来管理您的腾讯云资源。此外,您还可以基于腾讯云的命令行工具来做自动化和脚本处理,以更多样的方式进行组合和重用。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档