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

yipeiwu_com6年前Python基础

本文实例讲述了python从sqlite读取并显示数据的方法。分享给大家供大家参考。具体实现方法如下:

import cgi, os, sys
import sqlite3 as db
conn = db.connect('test.db')
cursor = conn.cursor()
conn.row_factory = db.Row
cursor.execute("select * from person")
rows = cursor.fetchall()
sys.stdout.write("Content-type: text.html\r\n\r\n")
sys.stdout.write("")
sys.stdout.write("<html><body><p>")
for row in rows:
  sys.stdout.write("%s %s %s" % (row[0],row[1],row[2]))
  sys.stdout.write("<br />")
sys.stdout.write("</p></body></html>")

希望本文所述对大家的Python程序设计有所帮助。

相关文章

python enumerate内置函数用法总结

python enumerate内置函数用法总结

这篇文章主要介绍了python enumerate内置函数用法总结,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 enumera...

Python自动化构建工具scons使用入门笔记

Python自动化构建工具scons使用入门笔记

这段时间用到了scons,这里总结下,也方便我以后查阅。 一、安装scons Linux环境(以CentOS为例) 1、yum安装 yum install scons 2、源码安装 下载...

Python使用sorted对字典的key或value排序

sorted函数 sorted(iterable,key,reverse) iterable 待排序的可迭代对象 key 对应的是个函数, 该函数用来决定选取用哪些值来进行排...

OpenCV哈里斯(Harris)角点检测的实现

OpenCV哈里斯(Harris)角点检测的实现

环境 pip install opencv-python==3.4.2.16 pip install opencv-contrib-python==3.4.2.16 理论 克里...

Django时区详解

引言 相信使用Django的各位开发者在存储时间的时候经常会遇到这样子的错误: RuntimeWarning: DateTimeField received a naive date...