Python教程
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;”
:
-
#/usr/bin/env python #coding:utf-8 import sys import os def getFileHashCode(filename,type): if not os.path.exists(filename): return [True,"找不到这个文件:"+filename] else: try: nameSpace=__import__("hashlib") except: return [True,"你 … 继续阅读“python 获取文件的MD5码等”
:
-
安装 https://pypi.python.org/pypi/redis/ https://github.com/andymccurdy/redis-py 参照官网,安装命令 sudopipinstallredis 或者 sudoeasy_installredis 亦或 源码包执行sudopythonsetup.pyinstall 实例python >>> import redis >>> r = redis.Redis(host=”172.16.64.17 … 继续阅读“python Redis的Python客户端实例”
:
-
import socket, traceback host = ” port = 51423 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.bind((host, port)) while 1: try: message, address = s.recvfrom(8192) print ‘Got data from’, … 继续阅读“python udp 服务器”
:
-
import os from os.path import join, getsize def getdirsize(dir): size = 0L for root, dirs, files in os.walk(dir): size += sum([getsize(join(root, name)) for name in files]) return size if __name__ == ‘__main__’: filesize = getdirsize(r’c:\windows’) p … 继续阅读“python获取文件夹大小的代码”
:
-
#coding=utf-8 __author__ = ‘dehua.li’ from datetime import * import datetime import csv import sys import time import string import os import os.path import pylab as plt rootdir=’/nethome/dehua.li/orderlifeCycleData/xingzheng’ writeFileDir="/net … 继续阅读“python处理csv数据(不具备参考功能)”
: