您好,登錄后才能下訂單哦!
本篇內(nèi)容主要講解“python接口常用封裝函數(shù)有哪些”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“python接口常用封裝函數(shù)有哪些”吧!
.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## 標(biāo)題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 # 封裝數(shù)據(jù)庫查詢單條操作 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 # 封裝數(shù)據(jù)庫查詢所有操作 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 # 封裝更改數(shù)據(jù)庫操作 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() # 封裝數(shù)據(jù)庫新增所有操作 def insert_into(sql): conn = get_db_conn() cur = conn.cursor() cur.execute(sql) conn.commit() result = cur.fetchall() conn.close() return result
到此,相信大家對“python接口常用封裝函數(shù)有哪些”有了更深的了解,不妨來實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。