#
#题目链接: Https://github.com/Yixiaohan/show-me-the-code
#
1. Backing up files
[email protected] ~]# cat backup_file.py import timeimport ossource=['/root/py/', '/root/tx ']target= '/tmp/' today_dir= Target+time.strftime ('%y%m%d ') time_dir=time.strftime ('%h%m%s ') touch =today_dir+os.sep+time_dir+ '. zip ' Command_ Touch = "ZIP-QR" +touch+ "+". Join (source) print (Command_touch) if os.path.exists (Today_dir) ==false:os.mkdir (Today_ DIR) if Os.system (Command_touch) ==0:print (' Success backup up ') else:print (' Failed back ') [[email protected] ~]#
0000.
#参考链接: PIL Example
From PIL import image,imagefont,imagedrawimport osdef modify_image (image_path,num=1): Img=image.open (Image_Path) mod _img=imagedraw.draw (IMG) myfont=imagefont.truetype (r "C:\Windows\Fonts\Verdana.ttf", Mod_img.text (img.size[1) *3/4,0), str (num), fill= (255,0,0), Font=myfont) save_path=os.path.dirname (image_path) +os.sep+ "Modify" + Os.path.splitext (Image_path) [1] img.save (save_path) if __name__== "__main__": Path=r "C:\Users\chauncey\Desktop\ C.jpg "Modify_image (path,4)
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/9E/0C/wKioL1mKpYvTjOiNAAAOK863Cok601.jpg "title=" Modify.jpg "alt=" Wkiol1mkpyvtjoinaaaok863cok601.jpg "/>
0001:
import uuiddef create_code (Num,length): result=[] while true: uid_4= Uuid.uuid4 () uid_1=uuid.uuid1 () x=str (uid_1). Replace ('-', ') y=str (uid_4). Replace ('-', ') result.append ((x+y) [: length]) if len (Result) ==num: break for code in result: print (code) if __name__== ' __main__ ': create_code (200,21)
================= restart:c:/users/chauncey/desktop/0001.py================= 5e742c9c7ccd11e79a0ef5e742c9d7ccd11e7b164f5e742c9e7ccd11e7a0baf5e742c9f7ccd11e79768f5e742ca07ccd11e79c95f5e742ca17ccd11e7 9d15f5e742ca27ccd11e7b8d2f5e742ca37ccd11e79cd6f5e742ca47ccd11e794d7f5e742ca57ccd11e79356f5e742ca67ccd11e7851cf5e742ca77cc D11E790FBF5E7453AE7CCD11E7983EF5E7453AF7CCD11E78775F5E7453B07CCD11E79590F5E7453B17CCD11E7A4F6F ...
0002 References: pymysql example
#mysqlmysql > delete from py_uuid_0002; query ok, 0 rows affected (0.00 sec) mysql> describe py_uuid_0002;+- ----------+-------------+------+-----+---------+-------+| field | type | Null | Key | Default | extra |+-----------+-------------+------+-----+---------+-------+| uuid_name | varchar (64) | YES | | NULL | |+-----------+-------------+------+-----+---------+-------+1 row in set (0.00 SEC) mysql> select count (*) from py_uuid_0002;+----------+| count (*) |+----------+| 201 |+----------+1 row in set (0.00 sec) #pythonimport uuidimport pymysqldef&Nbsp;create_code (num,length): result=[] while true: uid_4=uuid.uuid4 () UID_1=UUID.UUID1 () x=str (uid_1). Replace ('-', ') y=str (uid_4). Replace ('-', ') ' result.append ((x+y) [: Length]) if len (result) ==num: break return resultdef mysql_conn (host= "192.168.174.131", port=3307,user= "root", passwd= "123456", dbname= "test"): db=pymysql.connect (Host,user,passwd,dbname,port=port) cursor= Db.cursor () return db,cursordef mysql_exec (Db,cursor,result): for uuid_code in result: sql= "insert into py_uuid_0002 VALUES (' "+uuid_code+"); " try: cursor.execute (SQL) Db.commit () except: db.rollback () if __name__== ' __main__ ': result=create_code (201,21) db,cursor=mysql_conn () mysql_exec (Db,cursor,result) db.close ()
0003: Reference Link: Redis build redis List
Import uuidimport redisdef create_code (num,length): result=[] while true: uid_4=uuid.uuid4 ()        UID_1=UUID.UUID1 () x= STR (uid_1). Replace ('-', ') y=str (uid_4). Replace ('-', ') result.append ((x+y) [: length]) if len (Result) ==num: Break return resultdef save_redis (Result): r=redis. Redis (host= ' 192.168.174.128 ', port=7000,db=0) for uuid_code in result: r.lpush (' Uuid_code1 ', uuid_code) if __name__== ' __main__ ': result=crEate_code (200,21) save_redis (Result)
[[email protected] bin]#/redis-cli-p 7000127.0.0.1:7000> lrange ' uuid_code1 ' 5) "C2df0cfc7d0211e7b85ef" 2) "c2df0 CFB7D0211E78E3FF "3)" c2df0cfa7d0211e79ce3f "127.0.0.1:7000>
This article is from the "Chauncey" blog, make sure to keep this source http://cqwujiang.blog.51cto.com/10808946/1954954
Python Practice One