这段python代码对xapian的部分操作进行了简单的封装,希望对大家有用。import xapian, configfrom mmseg.search import seg_txt_2_dictclass Xapian(): """xapian search class """……继续阅读 » 水墨上仙 6年前 (2021-01-15) 1981浏览 1060个赞
xapian创建索引和搜索的简单范例程序,代码使用python实现 创建索引代码import sysimport osimport errnofrom contextlib import closingimport xapian as _xdef main(file……继续阅读 » 水墨上仙 6年前 (2021-01-15) 3009浏览 2269个赞
这是一段简单的python代码,用户转换不同单位的温度,适合初学者参考6061626364656667686970717273747576def c2f(t): return (t*9/5.0)+32def c2k(t): return t+273.15def f2c(t): return (t-32)……继续阅读 » 水墨上仙 6年前 (2021-01-15) 1732浏览 2454个赞
python编写的超简单端口转发程序代码非常简单,实现了简单的端口数据转发功能,用于真实环境还需要再修改一下。转自:http://blog.csdn.net/qffhq#tcp server import socket host = '127.0.0.1' #Local Server IP h……继续阅读 » 水墨上仙 6年前 (2021-01-15) 1677浏览 784个赞
xapian 通过python创建索引数据库的复杂一些的范例除了包含索引字符串外,还为索引添加了两个值#!/usr/bin/env python## Index each paragraph of a text file as a Xapian document.# Include some values that will be of use……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2473浏览 457个赞
这段代码需要调用serial模块,通过while循环不断读取串口数据转自:http://www.yelinsky.com/import timeimport serialser = serial.Serial( #下面这些参数根据情况修改 port='COM1', baudrate=9600, par……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2791浏览 1997个赞
python通过BF算法实现关键词匹配作者:smalltt#!/usr/bin/python# -*- coding: UTF-8# filename BFimport time"""t="this is a big apple,this is a big apple,this is a big ap……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2176浏览 2304个赞
python利用asyncore的端口映射(端口转发)可以实现端口数据的转发,效果还是不错的代码转自:http://www.cnblogs.com/nethirteimport socket,asyncoreclass forwarder(asyncore.dispatcher): def __init__(self, ip, port……继续阅读 » 水墨上仙 6年前 (2021-01-15) 3151浏览 330个赞
python读写文件方法汇总转自:http://blog.csdn.net/adupt/archive/2009/08/11/4435615.aspx 1.open使用open打开文件后一定要记得调用文件对象的close()方法。比如可以用try/finally语句来确保最后能关闭文件……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2740浏览 1041个赞
python getaddrinfo() 基本使用代码import sys, socketresult = socket.getaddrinfo("192.1.1.100", None)print result[0][4]print result 输出结……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2651浏览 2514个赞
这段代码可以生成5个不同的随机字母组成的长度为8的字符串import random, string for c in range(5): print random.sample(string.letters+string.digits, 8)……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2657浏览 2503个赞
python实现一个简单的基于SSL的 IRC bot的代码#!/usr/bin/python# -*- coding: utf8 -*- import socket, string, time, sslimport urllib, re network = 'irc.server.net'nick = 'n……继续阅读 » 水墨上仙 6年前 (2021-01-15) 3341浏览 653个赞
使用urllib和正则抓取和分析网页的简单代码片段import urllib, re url = 'http://www.viedemerde.fr/aleatoire'page = urllib.urlopen(url).read()parse = re.findall("\<div class=\&quo……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2433浏览 2073个赞
python编写的简单RPG游戏流程代码#RPGrpg = Truewhp = 100mahp = 100hhp = 100MHP = 10 def dgrnd () : wa = raw_input ("What does Warrior do?") ma = raw_input ("Wha……继续阅读 » 水墨上仙 6年前 (2021-01-15) 1616浏览 684个赞
将代码生成.py文件放在目录下运行,可以获取该目录的所有mp3文件的信息,需要使用ID3库import os, sysfrom ID3 import * files = os.listdir(os.getcwd()) for f in files: x = os.path.splitext(f) if x[1] == ……继续阅读 » 水墨上仙 6年前 (2021-01-15) 3100浏览 2827个赞
python将html表格转换成CSV使用方法:python html2csv.py *.html这段代码使用了 HTMLParser 模块#!/usr/bin/python# -*- coding: iso-8859-1 -*-# Hello, this program is written in Python - http://python.o……继续阅读 » 水墨上仙 6年前 (2021-01-15) 1812浏览 2552个赞
python根据主机名字获得所有ip地址# -*- coding: utf-8 -*-import sys, socketresult = socket.getaddrinfo('www.google.com', None, 0, socket.SOCK_STREAM)counter = 0for item in resul……继续阅读 » 水墨上仙 6年前 (2021-01-15) 1867浏览 443个赞
一个简单python ftp客户端代码#!/usr/bin/python# -*- coding: utf-8 -*-import ftplibimport osimport socketHOST = 'ftp.mozilla.org'DIRN = 'pub/mozilla.org/webtools'……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2010浏览 389个赞
一段简单的python邮件客户端发送代码#/usr/bin/python# -*- coding: utf-8 -*-import reimport smtplibfrom poplib import POP3from email.mime.text import MIMETextdef sevname(username): pa ……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2449浏览 452个赞
python实现自动登录人人网并采集信息的代码#!/usr/bin/python# -*- coding: utf-8 -*-import sysimport reimport urllib2import urllibimport cookielibclass Renren(object): def __init__(se……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2350浏览 1439个赞
python代码用于查找指定具有相同内容的文件,可以同时指定多个目录调用方式:python doublesdetector.py c:\;d:\;e:\ > doubles.txt# Hello, this script is written in Python - http://www.75271.com# doublesdetector.py 1……继续阅读 » 水墨上仙 6年前 (2021-01-15) 1861浏览 292个赞
python Gevent multiprocessing serverimport sysfrom gevent import serverfrom gevent.baseserver import _tcp_listenerfrom gevent.monkey import patch_all; patch_all()from multi……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2763浏览 889个赞
一个使用进程内通讯的python聊天室代码,非常简单的服务端和客户端代码#!/usr/bin/env python# Added by <ctang@redhat.com>import sysimport osfrom multiprocessing import connectionADDR = ('', 9……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2219浏览 2277个赞
这段代码可以对指定的目录进行扫描,包含子目录,对指定扩展名的文件进行SHA-1加密后存储在cvs文件,以防止文件被篡改调用方法:python snapper.py > todayCheck.csv# Hello, this is a script written in Python. See http://www.pyhon.org## Snapp……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2500浏览 2357个赞
我用这段代码来压缩数据库备份文件,没有使用python内置的zip模块,而是使用了zip.exe文件# Hello, this script is written in Python - http://www.75271.com## autozip.py 1.0p## This script will scan a directory (and……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2161浏览 2846个赞
这段python可以用来读取新闻组内的新闻,并保存为纯文本文件# Hello, this script is written in Python - http://www.75271.com## newsarchiver 1.1p - Newsgroup archiver## Purpose:# This script will dow……继续阅读 » 水墨上仙 6年前 (2021-01-15) 1741浏览 1603个赞
python打印ASCII编码字符代码i = 0while i < 256: print chr(i), if i != 0 and i % 8 == 0 : print i = i + 1……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2550浏览 908个赞
python实现的矩阵乘法def matrixMul(A, B): res = [[0] * len(B[0]) for i in range(len(A))] for i in range(len(A)): for j in range(len(B[0])): for k in range(le……继续阅读 » 水墨上仙 6年前 (2021-01-15) 3011浏览 111个赞
There is always room for optimizing primelist functions. Here is an assortment timed with Python module timeit …'''primelist_timing1.pytiming some very fas……继续阅读 » 水墨上仙 6年前 (2021-01-15) 3098浏览 1759个赞
This snippet allows one to implement an equivalent of a __getattr__() function in a python module. The module can then define its own way to lazily import abitrary symbols. For exa……继续阅读 » 水墨上仙 6年前 (2021-01-15) 3238浏览 388个赞
python从任意文件读取邮件地址输出,包括html、txt甚至exe文件调用方法:python email_extractor.py < PythonFAQ.html# Hello, this script is written in Python - http://www.75271.com# Script written by Sebastie……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2105浏览 1033个赞
python 操作 ssh#coding:utf-8""" ssh操作例子 实现了服务器日志下载 2012-08-24 yywolf"""import paramikoimport timehostname="????"port=22u……继续阅读 » 水墨上仙 6年前 (2021-01-15) 3291浏览 2606个赞
python统计cpu的利用率#-*-coding=utf-8-*-import win32pdhimport time# Counter pathsPROCESSOR_PERCENT = r'\Processor(_Total)\% Processor Time'MEMORY_PERCENT = r'\Memo……继续阅读 » 水墨上仙 6年前 (2021-01-15) 1772浏览 924个赞
python 使用socket远程发送命令并获得执行结果 #socket_server.pyimport socketimport osimport sysdef work(): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bind(……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2916浏览 1628个赞
python实现线程池原理:建立一个任务队列,然多个线程都从这个任务队列中取出任务然后执行,当然任务队列要加锁,详细请看代码出处:http://blog.csdn.net/liujian0616/article/details/7951081import threadingimport timeimport signalimport oscla……继续阅读 » 水墨上仙 6年前 (2021-01-15) 3061浏览 1345个赞
用python实现windows服务-在服务中新建进程出处:http://blog.csdn.net/liujian0616/article/details/7950758 需要安装的软件:python和pywin32,我这里装的分别是python-2.6.amd64、pywin32-……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2776浏览 1154个赞
python xmlrpc实现二进制文件传输的代码 服务器端from SimpleXMLRPCServer import SimpleXMLRPCServerimport xmlrpclib def python_logo(): handle = open(&quo……继续阅读 » 水墨上仙 6年前 (2021-01-15) 1805浏览 1551个赞
python urllib.urlencode用法演示>>> import urllib >>> params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0}) >>> f =……继续阅读 » 水墨上仙 6年前 (2021-01-15) 3309浏览 1420个赞
python写的FTP简单上传下载文件出自 “王伟” 博客,请务必保留此出处http://wangwei007.blog.51cto.com/68019/983638#!/usr/bin/env python # -*- coding: utf-8 -*- from ftplib import FTP def ftp_up(filenam……继续阅读 » 水墨上仙 6年前 (2021-01-15) 3123浏览 2716个赞
通过python自动连接ssh服务器#!/usr/bin/python#-*- coding:utf-8 -*-import sys, time, ostry: import pexpectexcept ImportError: print """ You must install ……继续阅读 » 水墨上仙 6年前 (2021-01-15) 1642浏览 569个赞
python判断文件和文件夹是否存在import osos.path.isfile('test.txt') #如果不存在就返回Falseos.path.exists(directory) #如果目录不存在就返回False……继续阅读 » 水墨上仙 6年前 (2021-01-15) 4047浏览 1392个赞
python通过urllib2提交http post请求#!/usr/bin/python #coding=utf-8 import urllib import urllib2 def post(url, data): req = urllib2.Request(url) data = urllib.……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2676浏览 2429个赞
python根据域名获得ip地址def getIp(domain): import socket myaddr = socket.getaddrinfo(domain,'http')[0][4][0] print(myaddr) 其中d……继续阅读 » 水墨上仙 6年前 (2021-01-15) 3425浏览 2030个赞
python 2.6 引入了itertools模块,使得排列组合的实现非常简单import itertools #排列:e.g., 4个数内选2个排列>>> print list(itertools.permutations([1,2,3,4],2)) [(1, 2), (1, 3), (1, 4), (2, 1), (2,……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2689浏览 2636个赞
Python从ftp服务器下载文件的代码#coding=utf-8''' ftp自动下载、自动上传脚本,可以递归目录操作'''from ftplib import FTPimport os,sys,string,datetime,timeimport socketclass MY……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2095浏览 439个赞