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. IS2009制作Oracle 静默安装包(一)感谢空白先生特许授权

    原文:IS2009制作Oracle 静默安装包(一)感谢空白先生特许授权 上一篇: MyEclipse中消除frame引起的“the file XXX can not be found.Please ...

  2. JavaScript超大整数加法

    原文:JavaScript超大整数加法 什么是「超大整数」? JavaScript 采用 IEEE754标准 中的浮点数算法来表示数字 Number. 我也没花时间去详细了解 IEEE754标准 ,但 ...

  3. tornado settings想到的

    今天有足够多的时间来看看Tornado中RequestHandler和Application这两个类的关系. 昨天想要调用settings中的内容,找了好半天不知道怎么在handler中使用setti ...

  4. windows 7 下快速搭建php环境(windows7+IIS7+php+mysql)

    原文:windows 7 下快速搭建php环境(windows7+IIS7+php+mysql) 1).采用理由: 优点:最大化的桌面图形化操作系统,可维护性优秀.基于IIS v6.0/v7.0(20 ...

  5. 检测浏览器版本类型的JavaScript代码,终极版

    下面的JavaScript代码,不仅可以判断PC端浏览器类型,还可以判断安卓.iOS.其他智能手机.平板电脑或游戏系统. 说废话貌似不是我的风格哈,直接上代码吧: var client = funct ...

  6. Mysql之IN 和 Exists 用法

    1.基本用法 IN:后面的子查询 是返回结果集的,换句话说执行次序和Exists()不一样.子查询先产生结果集,然后主查询再去结果集里去找符合要求的字段列表去.符合要求的输出,反之则不输出. Exis ...

  7. PhotoShop基本工具 -- 移动工具

    艺术或学习的东西吧, 爱好   比学编程还难 PS版本号 : PhotoShop CS6 1. 移动工具 (1) 工具栏和属性栏 工具栏 和 属性栏 : 左側的是工具栏, 每选中一个工具, 在菜单条的 ...

  8. Linux 安装配置maven3.0 以及搭建nexus私服

    http://carvin.iteye.com/blog/785365 一.软件准备 1.apache-maven-3.0-bin.tar.gz 下载地址:http://www.apache.org/ ...

  9. 解决C# WinForm 中 VSHOST.EXE 程序不关闭的问题

    右击“解决方案”--属性-调试栏-启用调试器部分-“启用Visual studio宿主进程”不勾选

  10. [置顶] c# 验证码生成

    今儿有一个任务是输出一串字符,要求用GDI画出于是: Bitmap bm = new Bitmap(200, 200);             Graphics g = Graphics.FromI ...