文章预览
50. 压缩文件: import zipfile with zipfile. ZipFile ( "file.zip" , "r" ) as zip_ref : zip_ref. extractall ( "extracted" ) 51. 数据库操作: import sqlite3 conn = sqlite3.connect( "my_database.db" ) cursor = conn.cursor() cursor.execute( "CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT)" ) conn.commit() conn.close() 52. 网络请求: import requests response = requests.get( "https://www.example.com" ) 53. 多线程: import threading def my_thread () : print( "Thread running" ) thread = threading. Thread (target=my_thread) thread. start () thread. join () 54. 多进程: import multiprocessing def my_process(): print ( "Process running" ) process = multiprocessing. Process (target=my_process) process. start () process. join () 55. 进程池: from multiprocessing import Pool def my_function ( x ): return x*x with Pool( 5 ) as p: print (p. map (my_function, [ 1 , 2 ,
………………………………