We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 1596754 commit 911eaa5Copy full SHA for 911eaa5
1 file changed
Liez-python-code/0002/0002.py
@@ -0,0 +1,35 @@
1
+# coding = utf-8
2
+__author__= 'liez'
3
+
4
+import random
5
+import sqlite3
6
7
+def make_number(num, length):
8
+ str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
9
+ a = []
10
+ i = 0
11
+ while i < num:
12
+ numstr = ''
13
+ for j in range(length):
14
+ numstr += random.choice(str)
15
+ if numstr not in a: #如果没重复
16
+ a.append(numstr)
17
+ i += 1
18
+ print(a)
19
+ return a
20
21
+def save(a):
22
+ try:
23
+ connect = sqlite3.connect('codelist.db')
24
+ except:
25
+ print("failed")
26
+ cur = connect.cursor()
27
+ cur.execute('create table if not exists codes(code char(20) primary key)')
28
+ for item in a:
29
+ cur.execute('insert into codes values (?)', [item])
30
+ print("success")
31
+ connect.commit()
32
+ cur.close()
33
+ connect.close()
34
35
+save(make_number(20, 10))
0 commit comments