File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 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 ))
You can’t perform that action at this time.
0 commit comments