#!/usr/bin/env python
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)
dtstr = ctime(dtint)
shorter = randint(4,7)
em = ''
for j in range(shorter):
em += choice(lowercase)
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)
输出结果
[huangcd@localhost ~]$ ./gendata.py
Wed Jul 20 17:08:17 1988::ukleh@nzbmmzjym.com::585389297-5-9
Wed Aug 13 02:15:04 2025::lcsbdj@kifdtkwqagr.edu::1755022504-6-11
Sun Sep 14 13:33:22 2008::rsyfmf@idvamc.gov::1221370402-6-6
Mon Jun 16 16:13:05 1975::kgusajh@yehctyykxp.gov::172138385-7-10
Tue Dec 29 00:07:50 2020::ocetyp@riszslao.net::1609171670-6-8
Thu Apr 13 04:51:29 2006::pancq@jfxlcqggi.net::1144875089-5-9
Thu Dec 23 09:11:01 2010::gneoy@ivdzbc.edu::1293066661-5-6
Thu May 9 00:28:34 1996::bwkhjs@xmjawpwebsb.com::831572914-6-11
Fri Nov 29 12:26:49 2002::rdhggh@rtpzhfbz.edu::1038544009-6-8
贪梦与飞贪梦
>>> date = 'Fri Nov 29 12:26:49 2002::rdhggh@rtpzhfbz.edu::1038544009-6-8'
>>> patt = '.+(\d+-\d+-\d+)'
>>> import re
>>> re.match(patt,date).group()
'Fri Nov 29 12:26:49 2002::rdhggh@rtpzhfbz.edu::1038544009-6-8'
>>> re.match(patt,date).group(1)
'9-6-8'
>>> patt = '.+?(\d+-\d+-\d+)'
>>> re.match(patt,date).group()
'Fri Nov 29 12:26:49 2002::rdhggh@rtpzhfbz.edu::1038544009-6-8'
>>> re.match(patt,date).group(1)
'1038544009-6-8'