关于python:0204-Python库faker

29次阅读

共计 784 个字符,预计需要花费 2 分钟才能阅读完成。

faker 库装置:

pip install faker 

应用参考博客:

Python-faker 的函数成果一览

集体应用参考代码:

# -*- coding:utf-8 -*-
__author__ = "leo"

from faker import Faker, Factory


class RandomTool:
    def __init__(self):
        self.fake = Faker(locale='zh_CN')  # 设置语言 -- 中文
        self.factory = Factory.create("zh_CN")  # 设置语言 -- 中文

    def create_username(self):
        username = self.factory.name()
        return username

    def create_id(self):
        number = self.fake.random_int()
        return number

    def create_phone(self):
        phone = self.fake.phone_number()
        return phone

    def create_email(self):
        email = self.fake.email()
        return email

    def create_department_name(self):
        department_name = self.fake.company()
        return department_name

# 实例化
random_tool = RandomTool()
USERNAME = random_tool.create_username()
ID = random_tool.create_id()
PHONE = random_tool.create_phone()
EMAIL = random_tool.create_email()
DEPARTMENT_NAME = random_tool.create_department_name()

正文完
 0