python中的faker库生成数据,并写入txt文本中

 

最近看文章,发现一个可以随机生成测试的python库:Faker。便动手实操了一下,并结合将结果写入txt中

faker库具体用法:http://testingpai.com/article/1615615023407

 

from faker import Faker
#from faker.providers import internet

fake = Faker(locale='zh-CN')


with open(r'C:\infror.txt','w',encoding='utf-8') as f:
    test_list=[]
    test_list.append(fake.name())
    test_list.append(fake.address())
    test_list.append(fake.email())


    for i in test_list:
        f.write(i)
        f.write("\n")

  

 

posted @ 2021-12-17 15:40  learn_py_test  阅读(360)  评论(0编辑  收藏  举报