Home > Backend Development > Python Tutorial > Detailed explanation of Python's method of reading and writing sqlite3 database and writing data to Excel

Detailed explanation of Python's method of reading and writing sqlite3 database and writing data to Excel

黄舟
Release: 2017-08-07 15:35:13
Original
4045 people have browsed it

这篇文章主要介绍了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)
Copy after login

数据库初始化方法:


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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template