Python教程
Python教程:包含了所有代写案例以及部分答案
-
python2.5以上版本已经集成了sqlite模块,下面是一些基本用法 #!/usr/bin/python # -*- coding: iso-8859-1 -*- from sqlite3 import dbapi2 as sqlite # Create a database: con = sqlite.connect(‘mydatabase.db3’) cur = con.cursor() # Create a table: cur.execute(‘create table client … 继续阅读“python操作sqlite”
:
-
这些天闲来无事就研究了下HTTP代理原理,顺便用Python做了个很挫的程序。 先来说说代理,所谓代理其实跟带话差不多。比方说A要跟C通信,但A和C之间没有通信渠道,这个时候就需要有一个和AC都能通信的中间人B来中转信息。搞懂了这个之后就需要考虑如何实现这样的一个代理服务器。 代理服务器必须得响应客户端请求,因此要建立一个监听Socket来接受客户端连接请求,y由于客户端不可能只有一个(因为就算一台电脑只有1个IP但他在访问网站时都会有很多端口同时连接上服务器),所以我们的代理服务器就得为每个客 … 继续阅读“Python实现HTTP代理服务器”
:
-
import xml.sax import os,sys class WordsHandler(xml.sax.ContentHandler): def __init__(self): self.CurrantTag = ” self.Word = ” self.Trans = ” self.wordfile = open(‘words.txt’, ‘w’) def startElement(self, tag, attributes): self.CurrantTag = tag def … 继续阅读“python 有道词典导出的xml生词本文件提取出单词”
:
-
#coding:utf-8 #author:Elvis class Stack(object): def __init__(self, size=8): self.stack = [] self.size = size self.top = -1 def is_empty(self): if self.top == -1: return True else: return False def is_full(self): if self.top +1 == self.size: return T … 继续阅读“python实现数据结构中的栈”
:
-
from os.path import basename, isdir from os import listdir def traverse(path, depth=0): print depth* ‘| ‘ + ‘|_’, basename(path) if(isdir(path)): for item in listdir(path): traverse(path+’/’+item, depth+1) if __name__ == ‘__main__’: traverse(‘./’) 标签 … 继续阅读“python遍历目录树代码”
:
-
#coding= utf-8 def findStr(ss, substr): if ss.find(substr) == -1: print "not fund" else: res = [] index = ss.find(substr) res.append(index) nlen = len(substr) ss = ss[index+nlen:] while ss != "": index = ss.find(substr) if index = … 继续阅读“python 在字符串ss中查找子串subsr的个数,并输出子串第一次出现的位置”
:
-
import http.cookiejar import urllib.request import urllib.parse from PIL import Image import gzip,re,random class Crawler_self: def __init__(self): self.Cr_header_data = { ‘Accept’:’text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/* … 继续阅读“python 任意生身份证号码(最新区域划分)”
:
-
# -*- coding: utf-8 -*- import sys import xlrd import json file = sys.argv[1] #print(file) data = xlrd.open_workbook(file) table=data.sheets()[0] nrows=table.nrows #print(nrows) ncols = table.ncols #print(ncols) returnData={} for i in range(nrows ): … 继续阅读“python 使用xlrd读取excel并返回json”
:
-
import Tkinter class mybutton: def __init__(self,root,canvas,label,types): self.root=root self.canvas=canvas self.label=label if types==0: button=Tkinter.Button(root,text=’Drawline’,command=self.Drawline) elif types==1: button=Tkinter.Button(root,tex … 继续阅读“python 闲来无事,,,,一个“画图amp;quot;”
: