In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
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!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.