账号包括大写,小写字母和数字,结尾以@163.com结尾

1 import string
 2 import random
 3 
 4 def file_w(str):
 5     with open('账号.txt','a+',encoding='utf-8') as f:
 6         f.seek(0)
 7         f.write(str + '\n')
 8         f.flush()
 9 
10 # def file_r():
11 #     lines=[]
12 #     with open('账号.txt',encoding='utf-8') as f:
13 #         for line in f:
14 #             lines.append(line)
15 #     return lines
16 
17 L1 = string.digits#数字
18 L2 = string.ascii_uppercase#大写字母
19 L3 = string.ascii_lowercase#小写字母
20 L4 = L1+L2+L3
21 def file_n(m):
22    n = input('请输入要生成的位数:')
23    n = int(n)
24    for i in range(m):
25         user = random.sample(L1,1)+random.sample(L2,1)+random.sample(L3,1)+random.sample(L4,n)
26         random.shuffle(user)
27         user = ''.join(user)+'@163.com'
28         file_w(user)
29 m = input('请输入要生成的条数:')
30 m = int(m)
31 file_n(m)

我这个没有判断新生成的账号是否存在,且在输入的时候没有对输入内容进行校验,请各位写的时候注意一下,等以后有时间了再补充完整