gpt4 book ai didi

python - 在 cursor.description 中避免 None ?

转载 作者:行者123 更新时间:2023-12-03 23:02:08 26 4
gpt4 key购买 nike

我在 Python 中使用 sqlite3。
我的 table :

cursor.execute("""create table student(rno int, name char(20), grade char, gender char, avg decimal(5,2), dob date);""")
其中 cursor 是我的光标对象的名称......
我使用 cursor.description 来显示列名。但是每个元组中有七个字符串,其中六个是 None
print(cursor.description)
Output : (('rno', None, None, None, None, None, None), ('name', None, None, None, None, None, None), ('grade', None, None, None, None, None, None), ('gender', None, None, None, None, None, None), ('avg', None, None, None, None, None, None), ('dob', None, None, None, None, None, None))
来自 API ,很明显每个元组的前两个元素是必须的。但这不适合我。为什么?
另外,我应该在我的表中进行哪些更改以获取设置为 None 的其他元素的值???
任何相关的帮助表示赞赏....

最佳答案

DB API2.0 的 sqlite3 只保证第一项。

it returns a 7-tuple for each column where the last six items of eachtuple are None.


https://docs.python.org/3/library/sqlite3.html#sqlite3.Cursor.description
要打印所有详细信息,我想您应该有一些数据。
可能是添加一些数据并执行选择语句

关于python - 在 cursor.description 中避免 None ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64962260/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com