打开文件中未加 ‘w’ 只写,with open('F:/pyxm/eric_file/users.txt','w')as f:,加上就可正常运行:
源码:
import random,string
def users(count,legth):
with open('F:/pyxm/eric_file/users.txt','w')as f:
for iin range(count):
str1=''.join(random.sample(string.ascii_letters,legth-1))
str2=''.join(random.sample(string.digits,3))
f.write(str1+ str2+'@163.com'+'\n')
count =int(input('请输入需要产生邮箱的个数:').strip())
legth =int(input('请输入邮箱的长度:').strip())
users(count,legth)
源码:
##批量生成邮箱
import random,string
def automail(num,len,lenzm):
with open('F:/pyxm/eric_file/users.txt','w')as f:
if len
print('邮箱的出现的数字要小于邮箱总的位数')
else:
for iin range(num):
str1=''.join(random.sample(string.ascii_letters,len-lenzm))
str2=''.join(random.sample(string.digits,lenzm))
str3=''.join(random.choice(['126.com','163.com','qq.com','Gmail.com']))
t_mail=str1+str2+'@'+str3
f.write(t_mail+'\n')
# print(t_mail)
num =int(input('请输入需要产生邮箱的个数:').strip())
len =int(input('请输入邮箱的长度:').strip())
lenzm=int(input('请输入邮箱名数字的长度:').strip())
automail(num,len,lenzm)
网友评论