这篇文章主要介绍了Python实现读写sqlite3数据库并将统计数据写入Excel的方法,涉及Python针对sqlite3数据库的读取及Excel文件相关操作技巧,需要的朋友可以参考下
本文实例讲述了Python实现读写sqlite3数据库并将统计数据写入Excel的方法。分享给大家供大家参考,具体如下:
src = 'F:\\log\\mha-041log\\rnd-log-dl.huawei.com\\test' # dst = sys.argv[2] dst = 'F:\\log\\mha-041log\\rnd-log-dl.huawei.com\\test\\mha-041log.db' # dst_anylyzed = sys.argv[3] dst_anylyzed = 'F:\\log\\mha-041log\\rnd-log-dl.huawei.com\\test\\mha-041log.xlsx' cx = sqlite3.connect(dst) init_table_title(cx, startcoreapp_table) init_table_title(cx, startwechat_table) init_table_title(cx, coreappjankframe_table) init_table_title(cx, wechatjankframe_table) init_table_title(cx, otherapp_table) os.path.walk(src, visit_zipfile, cx)
数据库初始化方法:
def init_table_title(c, work_table): global base_index global info_index c.execute('DROP TABLE IF EXISTS ' + work_table); c.execute('CREATE TABLE ' + work_table + ' \ (Product TEXT NOT NULL, \ Version TEXT NOT NULL, \ Imei TEXT NOT NULL, \ Date TEXT NOT NULL, \ Eventid TEXT NOT NULL, \ HappenTime TEXT NOT NULL, \ FIELDNAME TEXT NOT NULL, \ CASENAME TEXT NOT NULL)'); return
The above is the detailed content of Detailed explanation of Python's method of reading and writing sqlite3 database and writing data to Excel. For more information, please follow other related articles on the PHP Chinese website!