ITPub博客

首页 > 应用开发 > IT综合 > python 随机生成字符串数据

python 随机生成字符串数据

原创 IT综合 作者:huzhichengforce 时间:2014-10-29 16:54:07 0 删除 编辑
不说话字节贴代码:
# -*- coding:UTF-8 -*-
print ('---------------------------game---------------------------')
import re
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(10,20)): #循环 10-20次
    dtint = randint(0, maxint-1)#获得随机数
    dtstr = ctime(dtint) # 格式化时间
    shorter = randint(4,7)#获得随机数
    em = ''
    for j in range(shorter):#循环生成em
        em +=choice(lowercase)
    longer = randint(shorter,12) #domain
    dn = ''
    for j in range(longer):#循环生成dn
        dn += choice(lowercase)
    f=open('email.txt','a+')#打开文件以追加的方式,没有文件则创建文件
    x='%s::%s@%s.%s::%d-%d-%d' % (dtstr, em,dn, choice(doms), dtint, shorter, longer)+'\n'#得到我们想要的字符串一个循环得到一个字符串
    f.writelines(x)#写入文件
    f.close()#关闭文件
print ('---------------------------game---------------------------')


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26764973/viewspace-1313591/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 记录
请登录后发表评论 登录
全部评论

注册时间:2012-08-19

  • 博文量
    202
  • 访问量
    518270