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的更多相关文章

  1. xls/csv文件转换成dbf文件

    转至:https://blog.csdn.net/linhai1028/article/details/80211252 编写的一个小脚本,主要是利用python中的pandas,xlrd,dbfpy ...

  2. python sqlite3使用

    python sqlite3文档地址:http://docs.python.org/2/library/sqlite3.html The sqlite3 module was written by G ...

  3. python sqlite3 数据库操作

    python sqlite3 数据库操作 SQLite3是python的内置模块,是一款非常小巧的嵌入式开源数据库软件. 1. 导入Python SQLite数据库模块 import sqlite3 ...

  4. CSV文件在Python中的几种处理方式

    Comma Separated Values,简称CSV,它是一种以逗号分隔数值的文件类型.在数据库或电子表格中,它是最常见的导入导出格式,它以一种简单而明了的方式存储和共享数据,CSV文件通常以纯文 ...

  5. python sqlite3简单操作

    python sqlite3简单操作(原创)import sqlite3class CsqliteTable: def __init__(self): pass def linkSqlite3(sel ...

  6. python sqlite3 入门 (视频讲座)

    python sqlite3 入门 (视频讲座) an SQLite mini-series! - Simple Databases with Python 播放列表: YouTube https:/ ...

  7. 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") ...

  8. Python sqlite3操作笔记

    创建数据库 def create_tables(dbname): conn = sqlite3.connect(dbname) print "Opened database successf ...

  9. 基于Python+Sqlite3实现最简单的CRUD

    一.基本描述 使用Python,熟悉sqlite3的基本操作(查插删改),以及基本数据类型.事务(ACID).     准备工作:在sqlite3的官网上下载预编译的sqlite文件(windows) ...

随机推荐

  1. ThinkPHP框架设计与扩展总结

    详见:http://www.ucai.cn/blogdetail/7028?mid=1&f=5 可在线运行查看效果哦 导言:ThinkPHP框架是国内知名度很高应用很广泛的php框架,我们从一 ...

  2. Archlinux YouCompleteMe+syntastic vim自己主动补全插件,显示缩进和状态栏美化,爽心悦目的vim

    Archlinux 安装和配置vim补全插件YouCompleteMe的过程. 參考: https://github.com/Valloric/YouCompleteMe https://github ...

  3. C# - Recommendations for Abstract Classes vs. Interfaces

     The choice of whether to design your functionality as an interface or an abstract class can somet ...

  4. JavasScript实现调查问卷插件

    原文:JavasScript实现调查问卷插件 鄙人屌丝程序猿一枚,闲来无事,想尝试攻城师是感觉,于是乎搞了点小玩意.用js实现调查问卷,实现了常规的题型,单选,多选,排序,填空,矩阵等. 遂开源贴出来 ...

  5. BEGINNING SHAREPOINT® 2013 DEVELOPMENT 文件夹

    BEGINNING SHAREPOINT® 2013 DEVELOPMENT 文件夹 第一部分--開始使用SharePoint 2013 第1章节--SharePoint 2013 介绍 逐渐了解Sh ...

  6. SQL 无限级分类语句

    原文:SQL 无限级分类语句 原表数据为: 此处用到了with关键字,在程序中也可以用递归实现,但觉得还是没有一条sql方便 with tb (ID,Name,ParentID,Sort) as( s ...

  7. 题注Oracle数据库的网络连接原理

    版权声明:本文博客原创文章,博客,未经同意,不得转载.

  8. AngularJs ng-repeat

    AngularJs ng-repeat 必须注意的性能问题 AngularJs 的 ng-repeat 让我们非常方便的遍历数组生成 Dom 元素,但是使用不当也会有性能问题. 在项目中我们使用 ng ...

  9. Javascript技巧实例精选(5)—显示当前的日期和时间

    用Javascript实现在屏幕中打印当前的日期和时间 >>点击这里下载完整html源码<< 这是显示的效果 目前的日期/时间是:Wed Sep 25 2013 23:40:0 ...

  10. Matlab中如何用命令方式保存图像?

    命令很简单,例如下面这个代码将当前图像保存到F1.emf文件中,保存格式为emf saveas(gcf,'F.emf','emf'); 当然了,也可以保存为jpg格式,修改为: saveas(gcf, ...