您的位置:首页 > 编程语言 > Python开发

python核心编程-正则表达式-产生测试数据

2016-01-14 12:49 691 查看
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

from random import randint, choice
from string import lowercase
from sys import maxint
from time import ctime

doms = ('com', 'edu', 'net', 'org', 'gov')
for i in range(randint(5,10)):

dtint = randint(0, maxint-1)
print '1>>>>>> %d, %s' % (i,dtint)
dtstr = ctime(dtint)   # date string
print '2>>>>>> %s' % dtstr
shorter = randint(4,7)
print '3>>>>>> %d' % shorter
em = ''
for j in range(shorter):
print '4>>>>>> %d' % j
em += choice(lowercase)
print '5>>>>>> %s' % em
longer = randint(shorter, 12)
dn = ''
for j in range(longer):
dn += choice(lowercase)

print '%s::%s@%s.%s::%d-%d-%d' % (dtstr, em, dn, choice(doms), dtint, shorter, longer)


输出1:

E:\Python27\test>re11.py

1>>>>>> 0, 1237423144

2>>>>>> Thu Mar 19 08:39:04 2009

3>>>>>> 4

4>>>>>> 0

5>>>>>> q

4>>>>>> 1

5>>>>>> qm

4>>>>>> 2

5>>>>>> qmx

4>>>>>> 3

5>>>>>> qmxk

Thu Mar 19 08:39:04 2009::qmxk@jpcsmdnim.com::1237423144-4-9

1>>>>>> 1, 1512440820

2>>>>>> Tue Dec 05 10:27:00 2017

3>>>>>> 4

4>>>>>> 0

5>>>>>> i

4>>>>>> 1

5>>>>>> in

4>>>>>> 2

5>>>>>> inb

4>>>>>> 3

5>>>>>> inby

Tue Dec 05 10:27:00 2017::inby@qvsk.gov::1512440820-4-4

1>>>>>> 2, 643036442

2>>>>>> Fri May 18 21:14:02 1990

3>>>>>> 4

4>>>>>> 0

5>>>>>> j

4>>>>>> 1

5>>>>>> jl

4>>>>>> 2

5>>>>>> jlt

4>>>>>> 3

5>>>>>> jltx

Fri May 18 21:14:02 1990::jltx@avdbe.net::643036442-4-5

1>>>>>> 3, 1764332216

2>>>>>> Fri Nov 28 20:16:56 2025

3>>>>>> 4

4>>>>>> 0

5>>>>>> b

4>>>>>> 1

5>>>>>> bw

4>>>>>> 2

5>>>>>> bwq

4>>>>>> 3

5>>>>>> bwqc

Fri Nov 28 20:16:56 2025::bwqc@hzospynjrfa.com::1764332216-4-11

1>>>>>> 4, 659862141

2>>>>>> Thu Nov 29 15:02:21 1990

3>>>>>> 4

4>>>>>> 0

5>>>>>> c

4>>>>>> 1

5>>>>>> ca

4>>>>>> 2

5>>>>>> cat

4>>>>>> 3

5>>>>>> catr

Thu Nov 29 15:02:21 1990::catr@dcujgvntgjny.edu::659862141-4-12

1>>>>>> 5, 1828527776

2>>>>>> Sat Dec 11 20:22:56 2027

3>>>>>> 7

4>>>>>> 0

5>>>>>> v

4>>>>>> 1

5>>>>>> vj

4>>>>>> 2

5>>>>>> vji

4>>>>>> 3

5>>>>>> vjin

4>>>>>> 4

5>>>>>> vjinj

4>>>>>> 5

5>>>>>> vjinju

4>>>>>> 6

5>>>>>> vjinjum

Sat Dec 11 20:22:56 2027::vjinjum@dhbumxbgnc.com::1828527776-7-10

E:\Python27\test>

输出2:

E:\Python27\test>re11.py

Fri Jul 12 23:54:20 2013::mluriay@ivcodddebz.net::1373644460-7-10

Tue Jul 15 16:50:03 2031::jtmyrjm@dpbgdeycc.gov::1941871803-7-9

Thu Jan 18 05:19:55 2001::aljmo@dkebrayczsb.net::979766395-5-11

Thu Feb 12 14:19:23 1998::eypmrg@sviunptrta.net::887264363-6-10

Wed May 05 10:28:25 2010::hqkuq@gfgynqftvj.com::1273026505-5-10

Mon Mar 05 17:59:37 2029::rgxoed@secbzvfucb.com::1867399177-6-10

Sat Feb 25 08:46:28 2034::ffyhj@hopmyvg.edu::2024441188-5-7

Tue Apr 24 23:55:24 1984::hkbyuwo@upiaqjt.com::451670124-7-7
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: