
Python
文章平均质量分 54
ustcqi
这个作者很懒,什么都没留下…
展开
-
Python网络编程---TCP Server
import socketimport timeHOST = ''PORT = 12456ADDR = (HOST, PORT)bufferSize = 1024tcpServerSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)tcpServerSock.bind(ADDR)tcpServerSock.liste原创 2012-10-11 17:03:24 · 600 阅读 · 0 评论 -
计算某一个文件的行数
#_*_coding:utf_8_import sysimport os'''计算某一个文件的行数'''def countFileLines(filename): count = 0 try: handle = open(filename, 'r') for eachline in handle: count +=原创 2013-01-15 13:47:39 · 1116 阅读 · 0 评论 -
统计文件夹内.c .cpp .py类型文件的代码行数
#_*_coding:utf_8_import osimport globdef countFileLines(filename): count = 0 try: handle = open(filename, 'r') for eachline in handle: count += 1 except IOE原创 2013-01-15 14:15:05 · 938 阅读 · 0 评论 -
Code is to be happy
所有考试都结束了,静下来看看书,想到前几天想统计一下写过的代码行数,今天下午用了点时间弄了一下,代码写的不是很好,凑合看看吧,日后再整理一下.#_*_coding:utf_8_import osimport globfilefd = open('out.txt', 'w')def countFileLines(filename): count = 0 try:原创 2013-01-15 15:51:27 · 780 阅读 · 0 评论 -
统计文件夹内指定类型文件的代码行数(二)
#_*_coding:utf_8_import osimport globdef countFileLines(filename): count = 0 try: handle = open(filename, 'r') for eachline in handle: count += 1 except IOE原创 2013-01-15 14:24:09 · 1043 阅读 · 2 评论 -
Python访问sqlite3的入门操作
网上搜了下基本操作的代码, 感觉不错,用着挺方便.#_*_coding:utf_8_import sqlite3con = sqlite3.connect('D:\study\practice\python\sqlite3\mydb.db')#这个就是事务隔离级别,默认是需要自己commit才能修改数据库,置为None则自动每次修改都提交,否则为""con.isolation_lev原创 2013-01-16 11:23:20 · 863 阅读 · 0 评论 -
Python操作sqlite3数据库教程
导入数据模块: import sqlite3创建/打开数据库 conn = sqlite3.connect(dbName,encoding="cp936") conn = sqlite3.connect(':memory:') # 建立内存数据库连接 说明:调用connect函数的时候,指定库名称。如果指定的数据库存在,则打开;转载 2013-01-16 11:34:13 · 2725 阅读 · 0 评论 -
Python的MYSQLdb模块安装
1,查看是否已安装MySQLdb模块 进入python的命令行,输入 import MySQLdb 如果没有报错,证明此模块已经安装,可以跳过以下步骤。2,下载最新的MySQLdb安装包: wget -O python-1.2.3c1.tar.gz http://cdnetworks-kr-1.dl.sourceforge.net/project/mysql-py转载 2013-01-17 22:09:39 · 687 阅读 · 0 评论 -
用python和karrigell做网站.第一篇
用python和karrigell做网站.第一篇从今天起,和大家一起学习用python/karrigell做网站.对于能搜到这篇文章的兄弟,一定是对karrigell是什么有大致的了解了,但是如果不知道也没关系.这个单词虽然很复杂,而且金山词霸不知道该怎么解释,但实际上的意思却很简单.karrigell,一个支持用python开发web程序的框架,说的再明白一些,就是一个可以解释p转载 2013-01-18 16:12:17 · 2126 阅读 · 0 评论 -
BeautifulSoup帮助文档
Beautiful Soup 中文文档原文 by Leonard Richardson (leonardr@segfault.org) 翻译 by Richie Yan (richieyan@gmail.com) ###如果有些翻译的不准确或者难以理解,直接看例子吧。### 英文原文点这里Beautiful Soup 是用Python写的一个HTML/XML的解析器,它转载 2013-02-05 17:52:50 · 1676 阅读 · 0 评论 -
校内发状态的神器
#_*_coding:utf_8_from sgmllib import SGMLParserimport sys, urllib2, urllib, cookielibimport datetime, timeclass spider(SGMLParser): def __init__(self, email, password): SGMLPars转载 2013-02-09 17:20:37 · 770 阅读 · 0 评论 -
BeautifulSoup解析HTML(一)
用BeautifulSoup解析时要注意在有汉字的网页中编码解码问题,下面是获取大街网网页中class='jobInfo'的div标签的数据内容from bs4 import BeautifulSoupimport urllib2c = urllib2.urlopen('http://job.dajie.com/7262fae6-a1aa-4674-9efa-3baf697faa46.h原创 2013-03-08 19:07:33 · 1983 阅读 · 1 评论 -
Writing MySQL Scripts with Python DB-API
Writing MySQL Scripts with Python DB-APIPaul DuBoispaul@kitebird.comDocument revision: 1.02Last update: 2006-09-17Table of ContentsMySQLdb InstallationA Short转载 2013-03-10 11:02:37 · 999 阅读 · 0 评论 -
Python一行读入多个整数/字符串
import sysa , b , c = map(int,sys.stdin.readline().split())print a, b, c str1, str2 = map(str, sys.stdin.readline().split())print str1, str2做算法题时经常困惑如何像ACM那样输入的格式用Python来实现.,今天上网搜了一下,找到了,嘿嘿原创 2013-01-14 21:34:19 · 10467 阅读 · 0 评论 -
Python的二维数组
lists = [[] for i in range(3)]print lists lists[0].append(1)lists[1].append(2)lists[2].append(3)print listslists[0].append(3)print lists'''[[], [], []][[1], [2], [3]][[1, 3], [2], [3]]原创 2013-01-14 20:48:13 · 2112 阅读 · 0 评论 -
Python网络编程--TCP Client
import socketimport timeHOST = 'localhost'PORT = 12456ADDR = (HOST, PORT)bufferSize = 1024tcpClientSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)tcpClientSock.connect(ADDR)while原创 2012-10-11 17:04:29 · 747 阅读 · 0 评论 -
Python网络编程--UDP Server
import socketimport timeHOST = ''PORT = 12456ADDR = (HOST, PORT)bufferSize = 1024udpSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)udpSock.bind(ADDR)while True: print 'waiting原创 2012-10-11 17:06:54 · 647 阅读 · 0 评论 -
Python网络编程--UDP Client
import socketHOST = 'localhost'PORT = 12456ADDR = (HOST, PORT)bufferSize = 1024udpClientSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)while True: data = raw_input('>') if no原创 2012-10-11 17:07:43 · 751 阅读 · 0 评论 -
第二个解析HTML文件的Python程序
查看Python官网的文档,看了下关于HTMLParser模块的讲解,感觉不错,记录之。但是现在的疑问是用文件打开html文档和用HTMLParser对象直接读取文档最后输出结果不同,不知道原因,猜测应该是from HTMLParser import HTMLParserimport sysclass HTMLParser(HTMLParser): def handle_star原创 2012-10-26 22:10:36 · 978 阅读 · 0 评论 -
第一个解析HTML文件的Python程序
用HTMLParser模块解析HTML文件,一般要定义一个子类HTMLParser.HTMLParser,并添加用来处理不同标签的函数,这个程序用来提取标题titlemyTile.html my first html analyze program this is my text 下面使用python写的html文件解析代码#-*-原创 2012-10-26 21:47:51 · 1468 阅读 · 0 评论 -
第三个解析HTML文件的Python程序
#-*-coding:utf-8-*-from HTMLParser import HTMLParserfrom htmlentitydefs import name2codepointclass MyHTMLParser(HTMLParser): def handle_starttag(self, tag, attrs): print 'start ta原创 2012-10-27 19:47:54 · 769 阅读 · 0 评论 -
第四个解析HTML文件的Python程序
#-*-coding:utf-8-*-from HTMLParser import HTMLParserfrom htmlentitydefs import entitydefsimport sysclass TitleParser(HTMLParser): def __init__(self): self.title = '' self原创 2012-10-27 21:09:14 · 755 阅读 · 0 评论 -
第五个解析HTML文件的Python程序
#-*-coding:utf-8-*-from HTMLParser import HTMLParserimport sysfrom htmlentitydefs import name2codepointfrom htmlentitydefs import entitydefsclass TitleParser(HTMLParser): def __init__(s原创 2012-10-27 21:32:37 · 887 阅读 · 0 评论 -
Python版插入排序,归并排序,快速排序
由于写算法实验,用C++写的,最近学Python正好用Python实现熟练一下,发现简洁很多,用着太方便了下面贴代码,这俩个排序比较简单,不加注释了。#_*_coding:utf_8_import randomimport timeclass Sort(): def __int__(self): self.array = [] self.si原创 2012-12-17 21:51:06 · 840 阅读 · 0 评论 -
Python写的BloomFilter
由于Python没有内建的bitset数据结构,不过有需要自己安装的BitVector,用起来还是很方便的安装BitVector过程同Python安装第三方模块的方法: 命令行进入目录后,输入 python setup.py install 不过由于是在windows上做的实验,安装后只能在那个目录下使用BitVector这点有点迷惑,待解决...下面是我根据java版的Bloom原创 2013-01-24 13:19:33 · 5876 阅读 · 0 评论 -
Python的Dict版图遍历
#_*_coding:utf_8_import sysimport osclass Graph(): def __init__(self, V, E): self.V = V self.E = E self.visited = [] self.dict = {} self.fd = open("inpu原创 2013-01-24 14:10:33 · 1235 阅读 · 1 评论 -
Python版图的深度/广度搜索
#_*_coding:utf_8_import sysclass Graph(): def __init__(self): visited = [] edges = [[]] queue = [] V = 0 E = 0 def initGraph(self):原创 2013-01-14 22:17:27 · 1273 阅读 · 0 评论 -
Python建最小堆
直接贴代码,比较好懂#_*_coding:utf_8_'''建立一个最小堆'''import heapqimport randomclass MyHeap(): def __init__(self): self.n = 0 self.list = [] def buildHeap(self):原创 2013-01-15 13:31:21 · 1700 阅读 · 0 评论