Python-4.45 pymysql模块

  • pymysql模块之sql注入
    在这里插入图片描述
# pip3 install pymysql
import pymysql

user = input('user>>: ').strip()
pwd = input('password>>: ').strip()

# 建立链接
conn = pymysql.connect(
    host='localhost',
    user='root',
    password='',
    db='db9',
    charset='utf8'
)

# 拿到游标
cursor = conn.cursor()

# 执行sql语句
sql = 'select * from t1 where name = "%s" and pwd="%s"' % (user, pwd) # 注意%s需要加引号
rows = cursor.execute(sql)

cursor.close()
conn.close()

# 进行判断
if rows:
    print('登录成功')
else:
    print('登录失败')

# pip3 install pymysql
import pymysql

user = input('user>>: ').strip()
pwd = input('password>>: ').strip()

# 建立链接
conn = pymysql.connect(
    host='localhost',
    user='root',
    password='',
    db='db9',
    charset='utf8'
)

# 拿到游标
cursor = conn.cursor()

# 执行sql语句
# sql = 'select * from t1 where name = "%s" and pwd="%s"' % (user, pwd) #注意%s需要加引号
# rows = cursor.execute(sql)

sql = 'select * from t1 where name = %s and pwd= %s'  #!!!注意%s需要去掉引号,因为pymysql会自动为我们加上
rows = cursor.execute(sql, [user, pwd])

cursor.close()
conn.close()

# 进行判断
if rows:
    print('登录成功')
else:
    print('登录失败')
  • pymysql模块之增删改:conn.commit()
import pymysql

# 建立链接
conn = pymysql.connect(
    host='localhost',
    user='root',
    password='',
    db='db9',
    charset='utf8'
)

# 拿到游标
cursor = conn.cursor()

# 执行sql语句:增
sql = 'insert into t1 (name, pwd) values(%s,%s)'
rows = cursor.execute(sql, ('winnie6', '666666'))

conn.commit()
cursor.close()
conn.close()
# pip3 install pymysql
import pymysql

# 建立链接
conn = pymysql.connect(
    host='localhost',
    user='root',
    password='',
    db='db9',
    charset='utf8'
)

# 拿到游标
cursor = conn.cursor()

# 执行sql语句:增
sql = 'insert into t1 (name, pwd) values(%s,%s)'
rows = cursor.executemany(sql, [('winnie7', '777777'), ('winnie8', '888888'), ('winnie9', '999999')])

conn.commit()
cursor.close()
conn.close()
  • pymysql模块之查:fetchone,fetchmany,fetchall
import pymysql

# 建立链接
conn = pymysql.connect(
    host='localhost',
    user='root',
    password='',
    db='db9',
    charset='utf8'
)

# 拿到游标
cursor = conn.cursor()

# 执行sql语句:查询
rows = cursor.execute('select * from t1;')
print(cursor.fetchone())
print(cursor.fetchone())

conn.commit()
cursor.close()
conn.close()


结果:
(1, 'winnie1', 123456)
(2, 'winnie2', 111111)
import pymysql

# 建立链接
conn = pymysql.connect(
    host='localhost',
    user='root',
    password='',
    db='db9',
    charset='utf8'
)

# 拿到游标
cursor = conn.cursor()

# 执行sql语句:查询
rows = cursor.execute('select * from t1;')
print(cursor.fetchmany(2))

conn.commit()
cursor.close()
conn.close()

结果:
((1, 'winnie1', 123456), (2, 'winnie2', 111111))
import pymysql

# 建立链接
conn = pymysql.connect(
    host='localhost',
    user='root',
    password='',
    db='db9',
    charset='utf8'
)

# 拿到游标
cursor = conn.cursor()

# 执行sql语句:查询
rows = cursor.execute('select * from t1;')
print(cursor.fetchall())

conn.commit()
cursor.close()
conn.close()

import pymysql

# 建立链接
conn = pymysql.connect(
    host='localhost',
    user='root',
    password='',
    db='db9',
    charset='utf8'
)

# 拿到游标
cursor = conn.cursor()

# 执行sql语句:查询
rows = cursor.execute('select * from t1;')

cursor.scroll(3, mode='absolute')  # 相对绝对位置移动
print(cursor.fetchone())

conn.commit()
cursor.close()
conn.close()

结果:
(4, 'winnie4', 33333)
import pymysql

# 建立链接
conn = pymysql.connect(
    host='localhost',
    user='root',
    password='',
    db='db9',
    charset='utf8'
)

# 拿到游标
cursor = conn.cursor()

# 执行sql语句:查询
rows = cursor.execute('select * from t1;')

cursor.scroll(2, mode='relative')  # 相对当前位置移动
print(cursor.fetchone())

conn.commit()
cursor.close()
conn.close()

结果:
(3, 'winnie3', 22222)
### Transformers 4.45Python 兼容性要求 Transformers 库通常会遵循一定的最低 Python 版本支持标准。对于 `transformers` 版本 4.45 及以上,官方文档建议使用的最小 Python 版本为 3.8[^3]。 以下是关于环境配置的一些重要说明: #### 1. **Python 版本** - 官方推荐的最低 Python 版本为 3.8 或更高版本[^3]。 - 如果当前环境中使用的是低于 3.8 的 Python 版本,则可能无法安装或运行该库及其依赖项。 #### 2. **其他依赖包兼容性** - 需要注意的是,除了 Python 外,还需要确保其他相关依赖包(如 PyTorch 和 Accelerate)与 `transformers` 的最新版本保持一致。例如,在引用中提到的加速工具包 `accelerate==1.0.1` 已经被验证可以配合 `transformers==4.45.2` 使用[^1]。 #### 3. **具体命令中的依赖关系** - 在执行训练脚本时,通过 `torchrun` 命令调用了特定参数文件路径下的设置[^2]。这表明整个流程不仅涉及模型本身的加载,还涉及到分布式计算框架的支持。因此,需进一步确认所用的 PyTorch 是否满足最新的功能需求。 #### 示例代码:检查 Python 和 Transformer 版本 以下是一个简单的代码片段用于检测当前系统的 Python 和 `transformers` 版本是否匹配: ```python import sys from packaging import version import transformers required_python_version = (3, 8) if sys.version_info < required_python_version: print(f"Error: Your Python version {sys.version_info} is below the minimum requirement of {'.'.join(map(str, required_python_version))}.") else: print(f"Your Python version {sys.version_info} meets the requirements.") current_transformers_version = transformers.__version__ if version.parse(current_transformers_version) >= version.parse("4.45"): print(f"The installed 'transformers' version ({current_transformers_version}) is compatible.") else: print(f"The installed 'transformers' version ({current_transformers_version}) needs to be updated to at least 4.45.") ``` --- ###
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值