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求绝对值的三种方法小结

python求绝对值的三种方法小结

如下所示: 1.条件判断 2.内置函数abs() 3.内置模块 math.fabs abs() 与fabs()的区别 abs()是一个内置函数,而fabs()在math模块中定义的。...

python tornado使用流生成图片的例子

监控中,通常要使用图片更直观的看出集群的运行状况。 以下是一个简单的demo,通过rrdtool生成动态的图片。Python3, tornado. web.py templates/in...

Python计算一个文件里字数的方法

本文实例讲述了Python计算一个文件里字数的方法。分享给大家供大家参考。具体如下: 这段程序从所给文件中找出字数来。 from string import * def countW...

Python subprocess模块详细解读

Python subprocess模块详细解读

本文研究的主要是Python subprocess模块的相关内容,具体如下。 在学习这个模块前,我们先用Python的help()函数查看一下subprocess模块是干嘛的: DES...

python正则实现计算器功能

本文实例为大家分享了python正则实现计算器功能的具体代码,供大家参考,具体内容如下 # -*- coding: utf-8 -*- # Author :Gogh # @Ti...