forked from Show-Me-the-Code/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0002.py
More file actions
35 lines (31 loc) · 822 Bytes
/
0002.py
File metadata and controls
35 lines (31 loc) · 822 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
# coding = utf-8
__author__= 'liez'
import random
import sqlite3
def make_number(num, length):
str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
a = []
i = 0
while i < num:
numstr = ''
for j in range(length):
numstr += random.choice(str)
if numstr not in a: #如果没重复
a.append(numstr)
i += 1
print(a)
return a
def save(a):
try:
connect = sqlite3.connect('codelist.db')
except:
print("failed")
cur = connect.cursor()
cur.execute('create table if not exists codes(code char(20) primary key)')
for item in a:
cur.execute('insert into codes values (?)', [item])
print("success")
connect.commit()
cur.close()
connect.close()
save(make_number(20, 10))