sqlite3.OperationalError: unable to open database file
2016-01-21 14:43
661 查看
# -*- coding:utf-8 -*- ''' Created on 2016年1月12日 @author: Lux ''' import sqlite3 chromeHistoryDbPath = 'C:\Users\Lux\Desktop\History' class GetDbContent(): def __init__(self,path): self.dbpath = path def ReadTable(self): con = sqlite3.connect(self.dbpath) cur = con.cursor() tableList = cur.execute("select name from sqlite_master where type = 'table' order by name").fetchall() for table in tableList: print table[0] cur.close() if __name__ == '__main__': a = GetDbContent(chromeHistoryDbPath) a.ReadTable()
使用python连接sqlite数据库的文件的时候,不小心出现了错误
sqlite3.OperationalError: unable to open database file
百度了一下,错误有许多种,这里稍微列举一些
数据库路径最好写成绝对路径,并且目录要存在,而且 对目录要有读写的权限, 因为打开数据库的时候,会产生临时数据;
在Win 7 enterprise 和 Win Xp Pro上面写python v2.7时,
'C:\Users\Lux\Desktop\History'路径 有时候要写成
'C:\\Users\\Lux\\Desktop\\History';
有种情况我也是无法解释的,某些时候你的数据库文件后缀名不是
db也不行,需要改名为
xxx.db;
对数据库文件要有读写的权限;
相关文章推荐
- Android之获取手机上的图片和视频缩略图thumbnails
- Python动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 使用Python生成Excel格式的图片
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- Python中zip()函数用法举例
- Python中map()函数浅析
- 数据库链接字符串查询网站
- Python将excel导入到mysql中
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定