python学习杂记-生成假数据

在测试过程中,会有需要生成假数据的情况,可使用Faker模块来协助

文档位置https://faker.readthedocs.io/en/master/

使用此模块可以随机生成姓名,地址,email,password,文档等,还可以生成不同语言环境下的对应信息

安装:pip install Faker

 1 from faker import Faker
 2 
 3 f = Faker()
 4 # 随机生成姓名
 5 print(f.name()
 6 )# 随机生成地址
 7 print(f.address())
 8 # 随机生成email
 9 print(f.email())
10 # 随机生成password
11 print(f.password())
12 # 随机生成一段文本
13 print(f.text())
14 
15 #输出内容
16 Ryan Lee
17 0018 Victor Mills
18 Brewerberg, RI 59924
19 karen59@gmail.com
20 3Iqq20KuK%
21 Keep have well year thousand science. Close drop father list behind hand. Time he themselves break more.
22 
23 # 设置中文
24 f = Faker("zh_CN")
25 
26 print(f.name())
原文地址:https://www.cnblogs.com/RuiRuia/p/13212521.html