'''
Created on : 2023/12/21 20:22
@Author : ou
标题:faker简单用法
1、 pip install faker
2、 使用
'''
import time
from faker import Faker # 导入库
fk = Faker(locale="zh-CN")
# 一、四要素
# 1、姓名
name = fk.name()
# 2、身份证
id_card = fk.ssn()
# 3、手机号【项目中使用】
phone = fk.phone_number()
# 4、银行卡
card = fk.credit_card_number()
# 5、句子
sentence = fk.sentence()
# 个人信息
# 6、地址(包含邮编)
addr = fk.address()
print(addr)
# 6.1 单独邮编
post_code = fk.postcode()
print(post_code)
# 7、邮箱
email = fk.email()
print(email)
# 8、工作
job = fk.job()
print(job)
# 9、公司名称
comp = fk.company()
print(comp)
# 10、城市
city = fk.city()
print(city)
# 11、随机数、随即词
print(fk.random_int(100, 600))
print(fk.word())
# 12、时间
# 过去时间
print(fk.year(),type(fk.year()))
print(fk.month())
# 年月日 1970--至今
print(fk.date())
# 当前年份
print(fk.date_this_year())
# 当前月份
print(fk.date_this_month())
# 年月日时分秒
print(fk.date_time())
# 2个时间之间,精确到日 从当前时间往前数 -y年 -m月 today今天 --- 2022-01-03
print(fk.date_between(start_date="-2y",end_date="-1m"))
# 2个时间之间,精确到秒 从当前时间往前数 -y年 -m月 now现在时刻 --- 2023-08-10 06:20:45
print(fk.date_time_between(start_date="-2y",end_date="now"))
# 系统时间
print(time.time())
# time.strftime("%Y%m%d %H%M%S",time.time())
# # 时间戳
# print(fk.unix_time())
# 未来时间 futrue
print("-------未来时间-------")
# 造交易订单 对账(对平、挂账、销账)
future = fk.future_date() # 精确到日
print(future)
# 精确到秒
print(fk.future_datetime())
# 去重 同一个线程,产生不同的数据
fk.unique.name()
res = [fk.unique.name() for i in range(20)]
print(res)
2023.12 faker用法 四要素+个人信息
最新推荐文章于 2025-05-27 09:23:36 发布