File tree Expand file tree Collapse file tree 3 files changed +77
-0
lines changed
Expand file tree Collapse file tree 3 files changed +77
-0
lines changed Original file line number Diff line number Diff line change 1+ # coding = utf-8
2+ __author__ = 'Forec'
3+
4+ # 保随机码至MySQL
5+
6+ import pymysql
7+ import random
8+
9+ def make_number ( num , length ):
10+ letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
11+ dic = set ()
12+ i = 0
13+ while i < num :
14+ str = ''
15+ for j in range (length ):
16+ str += random .choice (letters )
17+ if str not in dic :
18+ dic |= {str }
19+ i += 1
20+ else :
21+ continue
22+ return dic
23+
24+ def save ( dic ):
25+ connect = pymysql .connect (
26+ host = '127.0.0.1' ,
27+ port = 3306 ,
28+ user = 'root' ,
29+ passwd = 'VKDARK'
30+ )
31+ cur = connect .cursor ()
32+ try :
33+ __create = 'create database if not exists test'
34+ cur .execute (__create )
35+ except :
36+ print ('database create error' )
37+ connect .select_db ('test' )
38+ __create_table = 'create table if not exists codes(code char(64))'
39+ cur .execute (__create_table )
40+ cur .executemany ('insert into codes values(%s)' ,dic )
41+
42+ connect .commit ()
43+ cur .close ()
44+ connect .close ()
45+
46+ save (make_number (200 ,10 ))
Original file line number Diff line number Diff line change 1+ import re
2+ with open ('input.txt' ,"r" ) as f :
3+ data = f .read ()
4+
5+ words = re .compile (r'([a-zA-Z]+)' )
6+ dic = {}
7+ for x in words .findall (data ):
8+ if x not in dic :
9+ dic [x ] = 1
10+ else :
11+ dic [x ] += 1
12+ L = []
13+ for k ,value in dic .items ():
14+ L .append ((k , value ))
15+
16+ L .sort (key = lambda t :t [0 ])
17+
18+ for x in L :
19+ print ( x [0 ], x [1 ])
Original file line number Diff line number Diff line change 1+ from PIL import Image , ImageOps
2+ import os , os .path
3+
4+ L = [ x for x in os .listdir ('.' ) if os .path .isfile (x ) and os .path .splitext (x )[1 ]== '.jpg' ]
5+
6+ for x in L :
7+ img = Image .open (x )
8+ xsize , ysize = img .size
9+ xsize = 500
10+ ysize = ysize * 500 // xsize
11+ img = ImageOps .fit (img ,(xsize ,ysize ))
12+ img .save ("out" + x )
You can’t perform that action at this time.
0 commit comments