python faker 生成随机类型字符串

以前生成测试字符时,用random模块拼来拼去来生成随机串,如姓名,手机,身份证等,还是费一些功夫,不过有了faker模块,一切变得简单起来

基本使用:

from faker import Faker
fake = Faker()
print fake.name()   # Jeffrey Freeman
fake = Faker("zh_CN")
print fake.name()  # 潘杨
print dir(fake)  # 可以看到所有随机方法。


fake = Faker()
try:
    for i in dir(fake):
        if hasattr(fake, i):
            func = getattr(fake, i)
            if i.startswith('_') or i in ['add_provider', 'format', 'binary','get_formatter', 'parse' ,'provider','providers','pytuple','random']:
                pass
            else:
                print i,':',func()

        else:
            print('操作有误,请重新输入')
except Exception as e:
    pass


address : 962 Brown Mountain
East Mary, CT 04738
am_pm : PM
ascii_company_email : dawnhines@cantrell.com
ascii_email : richardsanna@yahoo.com
ascii_free_email : ejohnson@yahoo.com
ascii_safe_email : steven92@example.org
bank_country : GB
bban : XRKR3466353844591
boolean : False
bothify : 16 zD
bs : harness cross-media web-readiness
building_number : 2202
catch_phrase : Quality-focused solution-oriented hierarchy
century : XII
chrome : Mozilla/5.0 (Macintosh; Intel Mac OS X 10_5_0) AppleWebKit/5352 (KHTML, like Gecko) Chrome/40.0.802.0 Safari/5352
city : New Lisa
city_prefix : Lake
city_suffix : town
color_name : Purple
company : Gray and Sons
company_email : martinallen@johnson.net
company_suffix : and Sons
coordinate : -87.141470
country : Northern Mariana Islands
country_code : SO
credit_card_expire : 12/27
credit_card_full : VISA 19 digit
Adam Murphy
4436102807805944284 02/22
CVC: 607

credit_card_number : 3508735520995723
credit_card_provider : American Express
credit_card_security_code : 129
cryptocurrency : ('BC', 'BlackCoin')
cryptocurrency_code : DRC
cryptocurrency_name : EOS.IO
currency : ('RWF', 'Rwandan franc')
currency_code : CHF
currency_name : São Tomé and Príncipe dobra
date : 2017-03-08
date_between : 2004-09-09
date_between_dates : 2019-01-02
date_object : 2016-06-06
date_of_birth : 1989-05-07
date_this_century : 2016-07-27
date_this_decade : 2015-06-18
date_this_month : 2019-01-01
date_this_year : 2019-01-01
date_time : 1998-05-01 17:23:46
date_time_ad : 0381-09-12 09:49:54
date_time_between : 2004-01-05 11:45:01
date_time_between_dates : 2019-01-02 20:42:43
date_time_this_century : 2008-12-05 18:31:25
date_time_this_decade : 2012-08-18 21:45:49
date_time_this_month : 2019-01-01 22:56:29
date_time_this_year : 2019-01-02 02:34:05
day_of_month : 09
day_of_week : Tuesday
domain_name : mendoza.biz
domain_word : zavala
ean : 4633017886662
ean13 : 1212638242694
ean8 : 00511063
ein : 27-4912026
email : ruizpeter@hotmail.com
file_extension : wav
file_name : close.jpg
file_path : /authority/section.mp4
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值