您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
本篇内容主要讲解“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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。