forked from techstay/python-study
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfaker_sample.py
More file actions
37 lines (24 loc) · 819 Bytes
/
faker_sample.py
File metadata and controls
37 lines (24 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from faker import Faker
import random
from pprint import pprint
from faker.providers import BaseProvider
fake = Faker('zh_CN')
print('----------自定义Provider-----------')
class Provider(BaseProvider):
def random_hello(self):
return random.choice(['hello', 'hi'])
fake.add_provider(Provider)
print(fake.random_hello())
print('----------一些随机数据-----------')
def generate_user():
return dict(name=fake.name(),
password=fake.password(length=10),
company=fake.company(),
job=fake.job(),
birthday=fake.date_of_birth(minimum_age=0, maximum_age=120),
telephone=fake.phone_number(),
address=fake.address())
users = []
for _ in range(0, 2):
users.append(generate_user())
pprint(users)