Python教程
Python教程:包含了所有代写案例以及部分答案
-
#沿左,右子节点较大者依次往下调整 def heapify( array, i, n ): j = i * 2 + 1 while j < n: if j + 1 < n and array[j] < array[j + 1]: j += 1 if array[i] > array[j]: break array[i], array[j] = array[j], array[i] i = j j = i * 2 + 1 #创建堆 def build_heap( array … 继续阅读“python实现堆排序”
:
-
python的socket库可以检测端口是否开放 import socket; sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) result = sock.connect_ex((‘127.0.0.1’,80)) if result == 0: print "Port is open" else: print "Port is not open" 这里sock.connect_ex方法尝试连 … 继续阅读“python检测端口是否开放”
:
-
def is_leap_year(Year): if Year % 4 == 0 and Year % 100 != 0 or Year % 400 == 0: return True else: return False def year_month_days(Year, Month): if Month in (1, 3, 5, 7, 8, 10, 12): return 31 elif Month in (4, 6, 9, 11): return 30 elif is_leap_year( … 继续阅读“python 你出生的那一年的那一个月的那一天是星期几”
:
-
requests是python的一个HTTP客户端库,和urllib、urllib2类似,但是urllib2的api比较复杂,比如像实现一个post或是get功能都得需要一大堆代码。 # -*- coding:utf8 -*- import request r = requests.get(‘http://www.zhidaow.com’)#发送请求 r.status_code#返回状态码 r.headers[‘content-type’]#返回头部信息 r.encoding#返回编码信息 r. … 继续阅读“python的HTTP客户端库requests使用示例”
:
-
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封装”
: