Python读取SQLite文件数据
![](https://images2017.cnblogs.com/blog/932612/201708/932612-20170818131227459-483088400.png)
![](https://images2017.cnblogs.com/blog/932612/201708/932612-20170818131244318-329620041.png)
- # -*- coding:utf8 -*-
- '''
- Author:Wang Yanlong
- Date: 2017-08-16
- All rights reserved.
- Distributed under the BSD license.
- References:
- https://docs.python.org/2/library/sqlite3.html (English)
- http://www.runoob.com/sqlite/sqlite-python.html (Chinese)
- '''
- import sqlite3 as db
- # 从SQLite文件中读取数据
- def readFronSqllite(db_path,exectCmd):
- conn = db.connect(db_path) # 该 API 打开一个到 SQLite 数据库文件 database 的链接,如果数据库成功打开,则返回一个连接对象
- cursor=conn.cursor() # 该例程创建一个 cursor,将在 Python 数据库编程中用到。
- conn.row_factory=db.Row # 可访问列信息
- cursor.execute(exectCmd) #该例程执行一个 SQL 语句
- rows=cursor.fetchall() #该例程获取查询结果集中所有(剩余)的行,返回一个列表。当没有可用的行时,则返回一个空的列表。
- return rows
- #print(rows[0][2]) # 选择某一列数据
- # 解析ARPA 单帧信息
- def readfromAppaFrame(ARPAFrame):
- subARPA=ARPAFrame.split(',')
- print(subARPA)
- if __name__=="__main__":
- rows=readFronSqllite('E://ARPA.db',"select ARPA from ARPAInfo")
- readLines=10010
- lineIndex=10000
- while lineIndex<readLines:
- row=rows[lineIndex] # 获取某一行的数据,类型是tuple
- content="".join(row) #tuple转字符串
- readfromAppaFrame(content) # 解析ARPA数据
- lineIndex+=1
***************************************
程序运行结果示例:
Python读取SQLite文件数据的更多相关文章
- python读取EXCLE文件数据
python读取EXCEL,利用 Google 搜索 Python Excel,点击第一条结果http://www.python-excel.org/ ,能够跨平台处理 Excel. 按照文档一步步去 ...
- python读取csv文件数据绘制图像,例子绘制天气每天最高最低气温气象图
- python使用h5py读取mat文件数据,并保存图像
1 安装h5py sudo apt-get install libhdf5-dev sudo pip install h5py 假设你已经安装好python和numpy模块 2 读取mat文件数据 i ...
- Python读取Yaml文件
近期看到好多使用Yaml文件做为配置文件或者数据文件的工程,随即也研究了下,发现Yaml有几个优点:可读性好.和脚本语言的交互性好(确实非常好).使用实现语言的数据类型.有一个一致的数据模型.易于实现 ...
- Python读取xlsx文件
Python读取xlsx文件 脚本如下: from openpyxl import load_workbook workbook = load_workbook(u'/tmp/test.xlsx') ...
- python读取yaml文件,在unittest中使用
python读取yaml文件使用,有两种方式: 1.使用ddt读取 2,使用方法读取ddt的内容,在使用方法中进行调用 1.使用ddt读取 @ddt.ddt class loginTestPage(u ...
- PHP 与Python 读取大文件的区别
php读取大文件的方法 <?php function readFile($file) { # 打开文件 $handle = fopen($file, 'rb'); while (feof($ ...
- 上传读取Excel文件数据
/// <summary> /// 上传读取Excel文件数据 /// 来自http://www.cnblogs.com/cielwater /// </summary> // ...
- cocos2d-x 3.0rc2中读取sqlite文件
cocos2d-x 3.0rc2中读取sqlite文件的方式,在Android中直接读取软件内的会失败.须要复制到可写的路径下 sqlite3* dbFile = NULL; std::string ...
随机推荐
- 201521123040《Java程序设计》第3周学习总结
1. 本周学习总结 初学面向对象,会学习到很多碎片化的概念与知识.尝试学会使用思维导图将这些碎片化的概念.知识组织起来.请使用纸笔或者下面的工具画出本周学习到的知识点.截图或者拍照上传.参考资料:百度 ...
- 自定义win8资源管理器左侧导航窗格的方法
Win8自定义资源管理器左侧导航窗格: 快捷键Win+R – 输入regedit: 删除“网络”项目 HKEY_CLASSES_ROOTCLSID{F02C1A0D-BE21-4350-88B0-73 ...
- 201521123117 《Java程序设计》第10周学习总结
1. 本周学习总结 2.2. 书面作业 1.finally 题目4-2 1.1 截图你的提交结果(出现学号) 1.2 4-2中finally中捕获异常需要注意什么? 只要try执行了之后,finall ...
- java课程设计(个人)--五子棋
1.团队课程设计博客链接 http://www.cnblogs.com/mz201521044152/p/7065575.html 2.个人负责模块说明 棋盘类,绘制棋盘,绘制棋子,按钮设置,鼠标监听 ...
- 201521123087《Java程序设计》第10周学习总结
1. 本周学习总结 2. 书面作业 本次PTA作业题集异常.多线程 finally题目4-21.1 截图你的提交结果(出现学号)1.2 4-2中finally中捕获异常需要注意什么? 用异常改进Arr ...
- 读取properties属性文件
1.通过类加载器加载 InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("Chap ...
- 嵌入系统squashfs挂载常见问题总结
由于squahsfs的一些优点,嵌入系统常常直接使用squashfs作为initrd挂载到/dev/ram,作为rootfs.这里对常见的一些问题进行一些分析. 1. kernel启动出现错误 RAM ...
- 引入Log4j
1. pom文件添加依赖 <!-- log start --> <dependency> <groupId>log4j</groupId> <ar ...
- D. How many trees? DP
D. How many trees? time limit per test 1 second memory limit per test 64 megabytes input standard in ...
- http://codeforces.com/contest/834
A. The Useless Toy time limit per test 1 second memory limit per test 256 megabytes input standard i ...