心碎的Basic SQL&Assignment
来源:互联网 发布:python搜索引擎书籍 编辑:程序博客网 时间:2024/04/29 13:55
import sqlite3conn = sqlite3.connect('emaildb.sqlite')cur = conn.cursor()#conn有点像文件的句柄cur.execute('''DROP TABLE IF EXISTS Counts''')cur.execute('''CREATE TABLE Counts (org TEXT, count INTEGER)''')fname = raw_input('Enter file name: ')if ( len(fname) < 1 ) : fname = 'mbox-short.txt'fh = open(fname)for line in fh: if not line.startswith('From: ') : continue email = line.split('@')[1].rstrip()#这里的rstrip()不能另外写一行 print email cur.execute('SELECT count FROM Counts WHERE org = ? ', (email, )) row = cur.fetchone() if row is None: cur.execute('''INSERT INTO Counts (org, count) VALUES ( ?, 1 )''', ( email, ) ) else : cur.execute('UPDATE Counts SET count=count+1 WHERE org = ?', (email, )) # This statement commits outstanding changes to disk each # time through the loop - the program can be made faster # by moving the commit so it runs only after the loop completesconn.commit()# https://www.sqlite.org/lang_select.htmlsqlstr = 'SELECT org, count FROM Counts ORDER BY count DESC'cur.execute(sqlstr)cur.close()
除了SQL语句以外都是老东西,参考下注释把,顺便说明一下邮箱的域名!!!
64949432@qq.com
域名是qq.com!!!!!
0 0
- 心碎的Basic SQL&Assignment
- 背叛之后的心碎
- 擦肩而过的心碎
- 我的心碎了
- 心碎
- 心碎
- Assignment 6: Basic Graph Algorithms
- 让我心碎的五道题
- 影史上最令人心碎的10个男人
- +心碎 在擾攘的街
- 在路上:玛拿西心碎的疯光
- 60句高傲得心碎的句子
- void man,心碎真的很好听!
- SQL Basic
- SQL-basic
- Assignment
- 电影史上最令人心碎的10个男人
- 我的两个同居女友 第28章 心碎伊拉克
- c中数据的存储(内存)
- Linux初认识(一)
- 人生感悟
- eclipse开发velocity实例(初学)
- View生成Bitmap
- 心碎的Basic SQL&Assignment
- Unity学习笔记四 - Survival Shooter Tutorial
- git操作详解
- 《CSS3实战》笔记--弹性盒模型(三)
- 使用gulp-sass 和 gulp-livereload 自动编译sass文件
- 240. Search a 2D Matrix II
- H5+css3+js搭建带验证码的登录页面
- Leetcode Increasing Triplet Subsequence
- LeetCode *** 221. Maximal Square