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. C语言 ## __VA_ARGS__ 宏

    在GNU C中,宏可以接受可变数目的参数,就象函数一样 可以把__VA_ARGS__看成是将...赋值给该宏 //注意这里不能在函数中调用abc() #include <stdio.h> ...

  2. 假如我来架构12306网站---文章来自csdn(Jackxin Xu IT技术专栏)

    (一)概论 序言:  此文的撰写始于国庆期间,当中由于工作过于繁忙而不断终止撰写,最近在设计另一个电商平台时再次萌发了完善此文并且发布此文的想法,期望自己的绵薄之力能够给予各位同行一些火花,共同推进国 ...

  3. PHP Warning: strtotime(): It is not safe to rely on the system's timezone settings.

    有三种解决办法: 1. php文件中设置时区 <?php date_default_timezone_set('Asia/Shanghai'); echo strtotime('2012-9-3 ...

  4. 深入浅出SQL Server 2008 分区函数和分区表

    原文:深入浅出SQL Server 2008 分区函数和分区表 当我们数据量比较大的时候,我们需要将大型表拆分为多个较小的表,则只访问部门数据的查询就可以更快的运行,基本原理就是,因为要扫描的数据变的 ...

  5. 淘宝code

    淘宝code 相信大家都听说过GitHub,也有很多人在用,但是GitHub毕竟在国外,速度不是很给力,而且安装过程也是很漫长.今天来给大家介绍一个国内的免费的开源项目平台,当然也是一个SVN版本控制 ...

  6. nagios 安装和配置(含有nrpe结束)所有 (两)

    二.ndoutils 安装: 1.mysql安装(若未安装) #apt-get install mysql-servermysql-client 2.DBI安装(若未安装) #cd /usr/loca ...

  7. jsp连接MySQL数据库显示GIS地理数据乱码问题的解决(select AsText(the_geom))

    oh,fuck,经过我昨天下午到今天的努力,终于将这一问题成功解决了,哈哈哈 问题详细描述: 我通过jsp页面连接上MySQL数据库,取出存在表中的地理数据(类型是geometry,具体有POINT. ...

  8. ASP.NET页面生命周期和asp.net应用程序生命周期

    作为一个asp.net程序员,不了解ASP.NET页面生命周期和asp.net应用程序生命周期是绝对不行的,那永远只能是菜鸟级别.我很早就学过,可是没次还是得去翻,一些事件还是记不住,还是记在自己的b ...

  9. 解决Github使用Fastly CDN而导致不能加载网页的方法

    Github现在基本属于“安全”网站,但 Github使用fastly.net的CDN服务后,其网站在国内经常不能正常加载网页.github.global.ssl.fastly.net的亚洲IP一般为 ...

  10. 【欧拉计划4】Largest palindrome product

    欢迎访问我的新博客:http://www.milkcu.com/blog/ 原文地址:http://www.milkcu.com/blog/archives/1371281760.html 原创:[欧 ...