您好,登錄后才能下訂單哦!
本篇內容主要講解“python接口常用封裝函數有哪些”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“python接口常用封裝函數有哪些”吧!
.def upload_image(pathName, pathRoute, pathType, keyName=None): ''' :param pathName: 圖片名稱 :param pathRoute: 圖片路徑 :param pathType: 圖片類型 :param keyName: 文件名稱 :return: ''' file = open(pathRoute, 'rb') files = { keyName: (pathName, file, pathType) } return files
def chepaihao(len='6'): char0 = '京津滬渝冀豫云遼黑湘皖魯新蘇浙贛鄂桂甘晉蒙陜吉閩贛粵青藏川寧瓊' char1 = 'ABCDEFGHJKLMNPQRSTUVWXYZ' # 車牌號中沒有I和O,可自行百度 char2 = '1234567890ABCDEFGHJKLMNPQRSTUVWXYZ' char3 = '1234567890' len0 = len(char0) - 1 len1 = len(char1) - 1 len2 = len(char2) - 1 len3 = len(char3) - 1 # while True: code = '' index0 = random.randint(1,len0) index1 = random.randint(1, len1) code += char0[index0] code += char1[index1] code += ' ' for i in ran## 標題ge(1, 5): index2 = random.randint(1, len2) code += char2[index2] index3 = random.randint(1,len3) code += char3[index3] # test = re.match('^.\w.[A-Z]\d{4}$|^.\w.\d[A-Z]\d{3}$|^.\w.\d{2}[A-Z]\d{2}$|^.\w.\d{3}[A-Z]\d$|^.\w.\d{5}$',code) print(code) return code
# 生成UUid def uuid_(): uid = uuid.uuid1() return uid.hex
import pymysql # 獲取連接方法 def get_db_conn(): conn = pymysql.connect(host='地址', port=000, # 端口號 user='name', passwd='23456', db='3454', # 庫名 cursorclass=pymysql.cursors.DictCursor) return conn # 封裝數據庫查詢單條操作 def query_db(sql): conn = get_db_conn() cur = conn.cursor() cur.execute(sql) conn.commit() result = cur.fetchone() cur.close() conn.close() return result # 封裝數據庫查詢所有操作 def query_all(sql): conn = get_db_conn() cur = conn.cursor() cur.execute(sql) conn.commit() result = cur.fetchall() cur.close() conn.close() return result # 封裝更改數據庫操作 def change_db(sql): conn = get_db_conn() cur = conn.cursor() try: cur.execute(sql) conn.commit() except Exception as e: conn.rollback() finally: cur.close() conn.close() # 封裝數據庫新增所有操作 def insert_into(sql): conn = get_db_conn() cur = conn.cursor() cur.execute(sql) conn.commit() result = cur.fetchall() conn.close() return result
到此,相信大家對“python接口常用封裝函數有哪些”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。