#!/usr/bin/python import sys def left_child(node): return node * 2 + 1 def right_child(node): return
算法优缺点 优点:在数据较少的情况下依然有效,可以处理多类别问题 缺点:对输入数据的准备方式敏感 适用数据类型:标称型数据 算法思想: 朴素贝叶斯 比如我们想判断一个邮件是不是垃圾邮件,那么我们知道的是这个邮件中的词的分布,那么我们还要知道:垃圾邮件中某些词的出现是多少,就可以利用贝叶斯定理得到。 朴素贝叶斯分类器中的一个假设是:每个特征同等重要 贝叶斯分类是一类分类算法的总称,这类算法均以贝叶斯
学了python以后,知道python的抓取功能其实是非常强大的,当然不能浪费,呵呵。我平时很喜欢美女图,呵呵,程序员很苦闷的,看看美女,养养眼,增加点乐趣。好,那就用python写一个美女图自动抓取程序吧~~
需要提醒的是,方法一,也就是通过uuid来实现的方法适用性更强一些,因为通过解析popen的数据还受到系统语言环境的影响,比如在中文环境 下"ipconfig/all"的结果就包含有中文,要查找mac地址的话就不能查找Physical
使用python 的 Tkinter实现一个简易计算器 #coding:utf-8 from Tkinter import * import time root = Tk() def cacl(input_str):
import urllib.request import re content = urllib.request.urlopen("http://www.open-open.com/") x = str(content.info()) match = re.search('charset=(?P<charset>\\w*)', x, re.IGNORECASE) if match: temp =
这些天闲来无事就研究了下HTTP代理原理,顺便用Python做了个很挫的程序。 先来说说代理,所谓代理其实跟带话差不多。比方说A要跟C通信,但A和C之间没有通信渠道,这个时候就需要有一个和AC都能
datetime(2009, 10, 7) dayCount = (d1 - d2).days python计算两个时间之间的秒数 import datetime starttime = datetime
# -*- coding: utf-8 -*- import Image,ImageDraw,ImageFont import random import math, string class RandomChar(): """用于随机生成汉字""" @staticmethod def Unicode(): val = random.randint(0x4E00, 0x9FBF) return u
msg['from'] = mail_user msg['subject'] = 'this is a python test mail' try: s = smtplib.SMTP() s.connect(mail_host)
#!/usr/bin/env python # coding=utf-8 import socket s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
#登陆邮箱 pwd = ''#邮箱密码 to = [''] #发送的邮箱 with open('D:\\Python源码\\city.txt','r') as f: a = f.read() station =
from PIL import Image, ImageFilter, ImageOps img = Image.open('C:\\Users\\hengli\\Pictures\\lovewallpaper\\214926-106.jpg') def dodge(a, b, alpha): return min(int(a*255/(256-b*alpha)), 255) def draw(i
txt中每行一个ip地址和端口号,代码可循环监控这些ip地址的指定端口是否正常 #!/usr/bin/env python # -*- coding: gbk -*- import socket,time while
python检测远程udp端口是否打开 import socket import threading import time import struct import Queue queue = Queue
python判断远程端口是否打开,下面的代码判断指定网站的80端口是否打开 import socket sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#!/usr/bin/env python 'makeFile.py -- create a file' import os ls = os.linesep # get filename while True:
#!/usr/bin/env python #! -*- coding: utf-8 -*- #图片地址样例:src="http://ww2.sinaimg.cn/large/005Yan1vjw1e
>>> import os >>> os.path.exists('d:/assist') True >>> os.path.exists('d:/assist/getTeacherList.py') True >>> os.path.isfile('d:/assist') False >>> os.path.isfile('d:/assist/getTeacherList.py') True >
利用socket包中的gethostname函数获取机器名之后,再调用gethostbyname函数获取机器的IP地址。 import socket def print_machine_info(): host_name = socket.gethostname() ip_address = socket.gethostbyname(host_name) print "Host name: %s"