Python教程
Python教程:包含了所有代写案例以及部分答案
-
#coding=utf-8 class AttrDisplay: def getAttrs(self): res = [] for key in self.__dict__: res.append("%s=%s"%(key, getattr(self, key))) return " ".join(res) def __str__(self): # attrs = AttrDisplay.getAttrs(self) return "[%s: % … 继续阅读“python 打印对象的属性”
:
-
OpenCV的人脸检测功能在一般场合还是不错的。而ubuntu正好提供了python-opencv这个包,用它可以方便地实现人脸检测的代码。 写代码之前应该先安装python-opencv: $ sudo apt-get install python-opencv 具体原理就不多说了,可以参考一下这篇文章。直接上源代码。 #!/usr/bin/python # -*- coding: UTF-8 -*- # face_detect.py # Face Detection using OpenCV … 继续阅读“python人脸识别”
:
-
初学者经常会遇到如何移除list中重复元素的问题。 这个问题在其他语言中可能需要for循环什么的,而在python中不用这样,非常简单,只需要将list作为set的构造函数构造一个set,然后再将set转换会list就可以了。 如下代码: myList = list(set(myList)) 下面是使用示例: >>> myList = [1, 2, 3, 3, 2, 2, 4, 5, 5] >>> myList [1, 2, 3, 3, 2, 2, 4, 5, … 继续阅读“Python去除list中的重复元素的最简单办法”
:
-
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小工具”
: