正则匹配 :以h开头以3结尾
import re
# line = 'h123'
#
# # 匹配
# match_res = re.match('h1234',line)
#
# if match_res:
# print('匹配成功')
# else:
# print('匹配失败')
# 以h开头后面跟着任意数量的字符
# line = 'h123eeee'
# line = 'h.22'
# line = 'h\\'
# print(len(line))
# line = 'h\\\\'
# print(len(line))
# line = 'h\\\\\\'
# print(len(line))
#
# # 匹配
# # match_res = re.match('h.',line)
# match_res = re.match('h\\\\',line)
#
# if match_res:
# print('匹配成功')
# else:
# print('匹配失败')
# re.match
# re.search
# re.compile
# 1. 以 h 开头
# 2. 以h开头后面跟着一个字符
# 3. 以h开头后面跟着任意数量的数字
# 4. 以3结尾
# 5. 以h开头,以3结尾,中间只有一个字符
# 6. 以h开头,以3结尾,中间可以存在任意数量的字符串
# 2.以h开头后面跟着一个字符
# line = 'h2222'
# match_res = re.match('h',line)
# if match_res:
# print('匹配成功')
# else:
# print('匹配失败')
链接mysql数据库 封装
import pymysql
# mysql_coon 主要功能是将链接数据库的操作变成只链接一次
class mysql_coon(object):
#初始化构造函数
def __init__(self):
# 链接数据库
self.db = pymysql.connect(host='127.0.0.1',user='root',password='123456',port=3306,database='data')
# 创建游标对象
self.cursor = self.db.cursor()
#执行modify(修改)的相关操作
def execute_modify_mysql(self,sql):
self.cursor.execute(sql)
self.db.commit()
#析构函数 关闭的时候触发
def __del__(self):
self.cursor.close()
self.db.close()
if __name__ == '__main__':
# 执行添加
sql = 'insert into datas values (1)'
# 实例化对象
mc = mysql_coon()
mc.execute_modify_mysql(sql)