`
cakin24
  • 浏览: 1328902 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论

python的sqlite的Row对象

阅读更多

一 代码

import sqlite3
conn=sqlite3.connect("test.db")
c=conn.cursor()
c.execute("DROP TABLE stocks")
c.execute('''CREATE TABLE stocks(data text,trans text,symbol text,qty real,price real)
''')
c.execute("""INSERT INTO stocks VALUES('2017-01-05','BUY','RHAT',100,35.14)""")
conn.commit()
conn.row_factory=sqlite3.Row
c=conn.cursor()
c.execute('SELECT * FROM stocks')
r=c.fetchone()
print(type(r))
print(tuple(r))
print(r[2])
print(r.keys())
print(r['qty'])
for field in r:
    print(field)
c.close()

 

二 运行结果
py =======
<class 'sqlite3.Row'>
('2017-01-05', 'BUY', 'RHAT', 100.0, 35.14)
RHAT
['data', 'trans', 'symbol', 'qty', 'price']
100.0
2017-01-05
BUY
RHAT
100.0
35.14
1
1
分享到:
评论

相关推荐

    python sqlite的Row对象操作示例

    主要介绍了python sqlite的Row对象操作,结合实例形式分析了Python使用sqlite的Row对象进行数据的查询操作相关实现技巧,需要的朋友可以参考下

    Python SQLite3数据库日期与时间常见函数用法分析

    本文实例讲述了Python SQLite3数据库日期与时间常见函数。分享给大家供大家参考,具体如下: import sqlite3 #con = sqlite3.connect('example.db') con = sqlite3.connect(":memory:") c = con.cursor() # Create ...

    python查询sqlite数据表的方法

    本文实例讲述了python查询sqlite数据表的方法。分享给大家供大家参考。具体实现方法如下: import sqlite3 as db conn = db.connect('mytest.db') conn.row_factory = db.Row cursor = conn.cursor() cursor....

    Python Sqlite3以字典形式返回查询结果的实现方法

    sqlite3本身并没有像pymysql一样原生提供字典形式的游标。 cursor = conn.cursor(pymysql.cursors.DictCursor) 但官方文档里已经有预留了相应的实现方案。 def dict_factory(cursor, row): d = {} for idx, ...

    python从sqlite读取并显示数据的方法

    本文实例讲述了python从sqlite读取并显示数据的方法。分享给大家供大家参考。具体实现方法如下: import cgi, os, sys import sqlite3 as db conn = db.connect('test.db') cursor = conn.cursor() conn.row_...

    aiosqlite:到标准sqlite3模块的异步桥

    aiosqlite:用于AsyncIO的Sqlite aiosqlite为sqlite数据库提供了一个友好的异步接口。 它复制标准的sqlite3... async for row in cursor: ... 它也可以以传统的程序方式使用: db = await aiosqlite.connect(...)

    Python实现Sqlite将字段当做索引进行查询的方法

    本文实例讲述了Python实现Sqlite将字段当做索引进行查询的方法。分享给大家供大家参考,具体如下: 默认从sqlite中获取到的数据是数字索引的, 在开发阶段经常有修改数据库所以显得不太方便, 其实在python源码里就有...

    python3.6.5参考手册 chm

    Python参考手册,官方正式版参考手册,chm版。以下摘取部分内容:Navigation index modules | next | Python » 3.6.5 Documentation » Python Documentation contents What’s New in Python What’s New In ...

    详解python中executemany和序列的使用方法

    详解python中executemany和序列的使用方法 一 代码 import sqlite3 persons=[ (Jim,Green), (Hu,jie) ] conn=sqlite3.connect(:memory:) conn.execute(CREATE TABLE person(firstname,lastname)) conn....

    Python Cookbook, 2nd Edition

    Python Cookbook, 2nd Edition By David Ascher, Alex Martelli, Anna Ravenscroft Publisher : O'Reilly Pub Date : March 2005 ISBN : 0-596-00797-3 Pages : 844 Copyright Preface The ...

    Foundations for Analytics with Python O-Reilly-2016-Clinton W. Brownley

    The chapter starts with examples that use Python’s built-in sqlite3 module so that you don’t have to install any additional software. The examples illustrate how to carry out some of the most ...

    pydbapi

    sqlite from pydbapi . api import SqliteDB db = SqliteDB ( database = None ) # 或者传入路径 sql = 'select * from [table];' row , action , result = db . execute ( sql ) 亚马逊Redshift from pydbapi . ...

Global site tag (gtag.js) - Google Analytics