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. AWK增强的文本处理shell特征--AWK完全手册

    AWK这是一个很好的文字处理工具. 它不仅 Linux 中也是不论什么环境中现有的功能最强大的数据处理引擎之中的一个. 本文主要摘录池中龙写的Unixawk使用手冊(第二版),对当中内容略微修改.感谢 ...

  2. sqlserver检测数据库是否能连接的小技巧

    有时候可能需要检测下某台机器的服务是不是起来了,或者某台机器的某个库是不是能被连接又不能打开ssms也不想登陆服务器的话就可以用这个方法. 1.在桌面上右键创建个文本,然后改后缀名为udl以后保存(1 ...

  3. UiAutomator源码分析之获取控件信息

    根据上一篇文章<UiAutomator源码分析之注入事件>开始时提到的计划,这一篇文章我们要分析的是第二点: 如何获取控件信息 我们在测试脚本中初始化一个UiObject的时候通常是像以下 ...

  4. C# 解析bt种子

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.C ...

  5. lua及luci学习

    由于项目需要对Luci进行修改,所以这里开始地luci进行较深入的研究. 探索其中的运行路径. Openwrt默认的HTTP服务器为uhttpd,该WEB服务器是由Luci的开发者自行开发的,非常小巧 ...

  6. iOS画面模糊

    增加  CoreImage.framework  CoreGraphic.framework 等库 在使用时引入:#import <Accelerate/Accelerate.h> ,支持 ...

  7. Memcached快递上手之C#

    Memcached快递上手之C# Memcached是开源高性能分布式缓存组件,目前已经广泛应用各类互联网领域. 具有多种语言的客户端开发包,包括:Perl/PHP/JAVA/C/Python/Rub ...

  8. Apache HttpServer Installing the apache2.2 service <OS 5>拒绝访问. :Failed to open the WinNT service manager

    Installing the apache2.2 service<OS 5>拒绝访问.  :Failed to open the WinNT service manager 只需要于管理员 ...

  9. 模仿c的字符转整数函数 atoi

    #include<stdio.h> , KInvalid}; int g_nStatus = KValid; long StrToIntCore(char *str,bool minus) ...

  10. Hashtable Dictionary List

    Hashtable Dictionary List 谁效率更高   一 前言 很少接触HashTable晚上回来简单看了看,然后做一些增加和移除的操作,就想和List 与 Dictionary比较下存 ...