由于工作中有时需要用到大批量数据,就自己手写个一段脚本,留下来以备将来需要,脚本如下:
# coding=utf-8
from faker import Faker
import time
import requests
import faker
import json
fake = Faker(locale="zh_CN")
def name():
return fake.last_name() + fake.first_name()
def address():
return fake.street_name()
def company():
return fake.company_prefix()
def phone_number():
return fake.phone_number()
def email():
return fake.email()
def car():
return fake.license_plate()
def write_info(fp, num):
fp.write("编号:%s
" % str(i + 1))
fp.write("姓名:%s
" % name())
fp.write("住址:%s
" % address())
fp.write("工作单位:%s
" % company())
fp.write("联系电话:%s
" % phone_number())
fp.write("邮箱:%s
" % email())
fp.write("汽车型号:%s
" % car())
fp.write("*" * 50)
fp.write("
")
if __name__ == "__main__":
fp = open(r"C:UsershzsyyDesktopASD.txt", "w", encoding='utf-8')
num = int(input("请输入要准备的人员数量: "))
begin_time = time.time()
for i in range(num):
write_info(fp, i)
fp.close()
total_time = time.time() - begin_time
print("造%d条数据共用%F秒" % (num, total_time))