forked from Show-Me-the-Code/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetCode.py
More file actions
39 lines (31 loc) · 816 Bytes
/
getCode.py
File metadata and controls
39 lines (31 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Created by xixijun
# Date: 15-5-13
# Blog: morningchen.com
import random
import string
# 字典域 由数字和字母(包括大小写)组成
FIELD = string.digits + string.letters
def generate(n, many=1, where=None):
"""
生成many组随机码
"""
def getCode(n):
"""
得到n位激活码
"""
return "".join(random.sample(FIELD, n))
gene = [getCode(n) for i in range(many)]
return gene
def writeIn(n, many, where):
"""
写入文件 并按顺序排列
"""
count = 1
for i in generate(n, many):
with open(where, "a") as boom:
boom.write(str(count).rjust(3)+" "+i+"\n")
count += 1
if __name__ == '__main__':
writeIn(20, 200, "coupon.txt")