What are the encapsulation functions commonly used in python interfaces
This article mainly explains "what are the commonly used encapsulation functions of the python interface", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "what are the commonly used encapsulation functions of the python interface?"
1. DEF upload_image (pathName, pathRoute, pathType, keyName=None):'': param pathName: picture name: param pathRoute: picture path: param pathType: picture type: param keyName: file name: return:''file = open (pathRoute,' rb') files = {keyName: (pathName, file, pathType)} return files2. Function of the encapsulated license plate def chepaihao (len='6'): char0 = 'Beijing, Tianjin, Shanghai, Chongqing, Hebei, Henan, Yunnan, Liao Black, Hunan, Anhui, New Jiangsu, Zhejiang, Jiangxi, Hubei, Guangxi, Gan, Jin, Shan, Ji, Fujian, Guangdong, Qinghai, Tibet, Sichuan Ningqiong' char1 = 'ABCDEFGHJKLMNPQRSTUVWXYZ' # there are no I and O in the license plate. Baidu char2 = '1234567890ABCDEFHJKLMNPQRSTUVWXYZ' char3 =' 1234567890' len0 = len (char0)-1 len1 = len (char1)-1 len2 = len (char2)-1 len3 = len (char3)-1 # while True: code =''index0 = random.randint (1line Len0) index1 = random.randint (1) Len1) code + = char0 [index0] code + = char1 [index1] code + =''for i in ran## title 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} [Amurz]\ d {2} $| ^.\ w.\ d {3} [Amurz]\ d$ | ^.\ w.\ d {5} $', code) print (code) return code3. Encapsulate the generate UUid function # generate UUiddef uuid_ (): uid = uuid.uuid1 () return uid.hex4. Encapsulate the function import pymysql# that connects to the database to get the connection method def get_db_conn (): conn = pymysql.connect (host=' address', port=000, # port number user='name', passwd='23456', db='3454' # Library name cursorclass=pymysql.cursors.DictCursor) return conn# encapsulates database query single operation 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# encapsulates database query all operations 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# encapsulates change database operation 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 () # Encapsulate all operations added to the database def insert_into (sql): conn = get_db_conn () cur = conn.cursor () cur.execute (sql) conn.commit () result = cur.fetchall () conn.close () return result to this I believe that everyone on the "python interface commonly used to encapsulate functions" have a deeper understanding, might as well to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!