xls===>csv tables===via python ===> sqlite3.db
I've got some files which can help a little bit to figure out where people are from based on their ID card NO.
That file looks like this:
Then I converted it into *.csv format which is basically a text file.
It's not hard that almost every common document editor has this functionality.
Here is my python codes:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
To store information into a sqlite database
Usage: $ python id2sql.py afile.csv idlist.db
This will invoke afile.csv to create a new database named idlist.db ---- Alex Liu '''
import sqlite3 as dbapi
import csv
import sys def createDB(path, destination):
'''
use the *.csv path to create a database file
'''
csvfilepath = path con = dbapi.connect(destination)
con.text_factory = str
cur = con.cursor()
cur.execute('CREATE TABLE idtable(code INTEGER, Region TEXT)')
try:
with open(csvfilepath,'rb') as idcsv: # 'rb' coz file csv is an obj
spamreader = csv.reader( idcsv, delimiter=',', quotechar='|')
for row in spamreader:
cur.execute( 'INSERT INTO idtable VALUES (?,?)',( row[1],row[2]) )
con.commit() # To update database
return "database %s updated! :)" % destination
except:
return "check the source codes again :(" if __name__=="__main__":
print createDB(sys.argv[1], sys.argv[2])
Run it:
Then, use the sqlite brrowser to check it out:
You could see the whole content of it :)
Isn't good ??
Ha Ha Have fun!!
xls===>csv tables===via python ===> sqlite3.db的更多相关文章
- xls/csv文件转换成dbf文件
转至:https://blog.csdn.net/linhai1028/article/details/80211252 编写的一个小脚本,主要是利用python中的pandas,xlrd,dbfpy ...
- python sqlite3使用
python sqlite3文档地址:http://docs.python.org/2/library/sqlite3.html The sqlite3 module was written by G ...
- python sqlite3 数据库操作
python sqlite3 数据库操作 SQLite3是python的内置模块,是一款非常小巧的嵌入式开源数据库软件. 1. 导入Python SQLite数据库模块 import sqlite3 ...
- CSV文件在Python中的几种处理方式
Comma Separated Values,简称CSV,它是一种以逗号分隔数值的文件类型.在数据库或电子表格中,它是最常见的导入导出格式,它以一种简单而明了的方式存储和共享数据,CSV文件通常以纯文 ...
- python sqlite3简单操作
python sqlite3简单操作(原创)import sqlite3class CsqliteTable: def __init__(self): pass def linkSqlite3(sel ...
- python sqlite3 入门 (视频讲座)
python sqlite3 入门 (视频讲座) an SQLite mini-series! - Simple Databases with Python 播放列表: YouTube https:/ ...
- VS2017 Git failed with a fatal error. error: open(".vs/xxxxxx/v15/Server/sqlite3/db.lock"): Permission denied fatal: Unable to process path .vs/xxxxxx/v15/Server/sqlite3/db.lock
具体错误信息:Git failed with a fatal error. error: open(".vs/xxxxxx/v15/Server/sqlite3/db.lock") ...
- Python sqlite3操作笔记
创建数据库 def create_tables(dbname): conn = sqlite3.connect(dbname) print "Opened database successf ...
- 基于Python+Sqlite3实现最简单的CRUD
一.基本描述 使用Python,熟悉sqlite3的基本操作(查插删改),以及基本数据类型.事务(ACID). 准备工作:在sqlite3的官网上下载预编译的sqlite文件(windows) ...
随机推荐
- IIS7伪静态化URL Rewrite模块
原文 IIS7伪静态化URL Rewrite模块 在Win7安装了IIS7.5之后,搭建一些网站或者博客,但是IIS7.5本身没有URL Rewrite功能,也就是无法实现网址的伪静态化. 从网上找了 ...
- Swift入门教程:基本语法(一)
简介: 什么是S ...
- What is HHVM?
What is HHVM? HHVM is an open-source virtual machine designed for executing programs written in Hack ...
- RethinkDB创始人教你如何打造一个伟大的互联网产品
关于作者 我叫Slava Akhmechet,本人是 RethinkDB 的创始人之一,RethinkDB是开源,分布式数据库,旨在帮助开发人员与运营商在打造实时应用时处理无结构数据 如何打造一个伟大 ...
- 查询DBlink创建
DBlink创建 查询 博客分类: Oracle 当用户要跨本地数据库,访问另外一个数据库表中的数据时,本地数据库中必须创建了远程数据库的dblink,通过dblink本地数据库可以像访问本地数据 ...
- JAVA基本的编程50称号(7-9称号)详细解释
一个.叙述性说明 1.输入一行字符.在这些信件统计.空格.出现频率的数字和其他字符的总数和每一个字符. 程序分析:使用String类的matchs()分别统计符合正則表達式的每类字符的 ...
- HTML5 五彩圆环Loading加载动画实现教程
原文:HTML5 五彩圆环Loading加载动画实现教程 今天我们要来介绍一款效果很特别的HTML5 Loading加载动画,不像其他的Loading动画,这款Loading动画颜色很丰富,并且在转圈 ...
- SQL点滴14—编辑数据
原文:SQL点滴14-编辑数据 数据库中的数据编辑是我们遇到的最频繁的工作,这一个随笔中我来总结一下最常用的数据编辑. select into 经常遇到一种情况是,我们希望创建一个新表,表中的数据来源 ...
- Wijmo 5 + Ionic Framework之:费用跟踪 App
Wijmo 5 + Ionic Framework之:费用跟踪 App 费用跟踪应用采用了Wijmo5和Ionic Framework创建,目的是构建一个hybird app. 我们基于<Mob ...
- 【转】浏览器DNS 预取读技术的危害
今天中午在http://news.ycombinator.com/news看到一篇文章标题: Saved 10 billion DNS queries per month by disabling D ...