Python教程
Python教程:包含了所有代写案例以及部分答案
-
python监控本机cpu的利用百分比情况“`python import wmi import time c = wmi.WMI() while True: for cpu in c.Win32_Processor(): timestamp = time.strftime(‘%a, %d %b %Y %H:%M:%S’, time.localtime()) print ‘%s | Utilization: %s: %d %%’ % (t … 继续阅读“python监控本机cpu的利用百分比情况”
:
-
# -*- coding: utf-8 -*- from xmlrpclib import ServerProxy, Fault from os.path import join, isfile, abspath from SimpleXMLRPCServer import SimpleXMLRPCServer from urlparse import urlparse import sys import xmlrpclib SimpleXMLRPCServer.allow_reuse_addr … 继续阅读“python 用XML_RPC实现P2P”
:
-
#!/usr/bin/env python #coding:utf-8 import urllib2 import re import os def getHtml(url): #获取html源码 headers={"User-Agent":"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1"} req=urllib2.Request(url,headers=headers) response=urllib … 继续阅读“python 翻页抓取”
:
-
# -*- coding: utf-8 -*- from PyQt4 import QtCore, QtGui from PyQt4.QtCore import * from PyQt4.QtGui import * from modules.UrlGet import UrlGet from modules.SameSite import SameSite import resource.resources class Main_Window(QMainWindow): def __init_ … 继续阅读“python web小工具”
:
-
#!/usr/bin/env python #coding: utf-8 import md5 import os from time import clock as now def getmd5(filename): file_txt = open(filename, ‘rb’).read() m = md5.new(file_txt) return m.hexdigest() def main(): path = u’C:\\aa\bb\cc\dd’ all_md5 = {} all_siz … 继续阅读“Python删除同一个文件夹下的重复文件代码”
:
-
#!/usr/bin/env python #-*- coding:utf-8-*- from mysql import connector def connect(): config={ ‘host’:’localhost’,#默认127.0.0.1 ‘user’:’root’, ‘password’:’1111111′, ‘port’:3306 ,#默认即为3306 ‘database’:’test’, ‘charset’:’utf8’#默认即为utf8 } try: return conn … 继续阅读“python Mysql connector封装”
:
-
下面是一个基础的python线程控制类 #!/usr/bin/env python """ testthread.py An example of an idiom for controling threads Doug Fort http://www.dougfort.net """ import threading class TestThread(threading.Thread): """ A sa … 继续阅读“Python的线程控制类”
:
-
def iquery(conn, sql, rowfactory=tuple, batch=1, *args, **kwgs): """在给定的数据库连接conn上执行sql(可带有参数*args或命名参数**kwgs) rowfactory指定输出物为元组/字典(或字典的扩展类) /或使用用命名参数的函数的结果 batch <= 0时, 直接全部输出 batch == 1时, 逐记录输出 batch >= 1时, 按指定的数量形成批次列表 " … 继续阅读“python common iter query”
:
-
#coding:utf-8 import struct codeDict={}#全局字典key=字符,value=数字 encodeDict={} filename=None listForEveryByte=[] class Node: def __init__(self,right=None,left=None,parent=None,weight=0,charcode=None): self.right=right self.left=left self.parent=parent sel … 继续阅读“Python实现的哈夫曼编码”
:
-
”’ print the "Hello, world!" on the console ”’ import os ”’ read data in file ”’ class File: def __init__(self): self.data = os.getcwd()+’\\data.txt’ self.datalines = self.readDataToList() def readDataToList(self): data = [] try: file = … 继续阅读“python初学之helloworld”
: