Python_查看sqlite3表结构,查询语句的示例代码

yipeiwu_com6年前Python基础

如下所示:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
 
import sqlite3
 
conn = sqlite3.connect('test.db')
# 创建一个Cursor:
cursor = conn.cursor()
 
# 查询记录:
conn = sqlite3.connect('calendar.db')
cursor = conn.cursor()
# 执行查询语句:
cursor.execute('select * from perpetualCalendar')
# 获得查询结果集:
values = cursor.fetchall()
print(values)
 
# cursor.execute('PRAGMA table_info(perpetualCalendar)')
print (cursor.fetchall())
cursor.close()
conn.close()

查看表结构:cursor.execute('PRAGMA table_info(表名)')

以上这篇Python_查看sqlite3表结构,查询语句的示例代码就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python 分发包中添加额外文件的方法

在制作一个 Python 分发包时经常需要把一些文件添加到包中。最常见的例子是你希望通过  pip install 命令安装 Python 包时会在  /etc/ 等...

Python 解码Base64 得到码流格式文本实例

我就废话不多说了,直接上代码吧! # coding:utf8 import base64 def BaseToFlow(): while True: str =...

python内置数据类型之列表操作

 数据类型是一种值的集合以及定义在这种值上的一组操作。一切语言的基础都是数据结构,所以打好基础对于后面的学习会有百利而无一害的作用。   python内置的常用数据类型有:数字、字符串...

Pandas之Dropna滤除缺失数据的实现方法

约定: import pandas as pd import numpy as np from numpy import nan as NaN 滤除缺失数据 pandas的设计目...

Python读取图片EXIF信息类库介绍和使用实例

首先要介绍的是 Python Imaging Library,使用方法如下: 复制代码 代码如下: from PIL import Image from PIL.ExifTags imp...