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"
exif-py是一个纯python实现的获取图片元数据的python库,官方下载地址: http://exif-py.svn.sourceforge.net/viewvc/exif-py/source/EXIF
Tkinter, PIL and data_stream tested with Python27 and Python33 by vegaseat 01mar2013 ''' import io # allows
wx.Sound(fileName, isResource=False) tested with Python27 and wxPython291 by vegaseat 25jul2013 ''' import
import ftplib ftp = ftblib.FTP("ftp.yourServer.com") ftp.login("username", "password") filename = "index.html" ftp.storlines("STOR " + filename, open(filename)) filename="app.exe" ftp.storbinary("STOR
# -*- coding: utf-8 -*- #导入三个模块 import Image,ImageDraw,ImageFont import random import math '''基本功能''' #图片宽度 width = 100 #图片高度 height = 40 #背景颜色 bgcolor = (255,255,255) #生成背景图片 image = Image.new('RGB',