python采集百度百科代码演示#!/usr/bin/python# -*- coding: utf-8 -*-#encoding=utf-8 #Filename:get_baike.pyimport urllib2,reimport sysdef getHtml(url,time=10): response = urllib2……继续阅读 » 水墨上仙 5年前 (2021-03-05) 2142浏览 748个赞
局域网内有一百多台电脑,全部都是linux操作系统,所有电脑配置相同,系统完全相同(包括用户名和密码),ip地址是自动分配的。现在有个任务是在这些电脑上执行某些命令,者说进行某些操作,比如安装某些软件,拷贝某些文件,批量关机等。如果一台一台得手工去操作,费时又费力,如果要进行多个操作就更麻烦啦。 或许你会想到网络同传, 网络同传是什么?就……继续阅读 » 水墨上仙 5年前 (2021-03-05) 1793浏览 2812个赞
python的threading和multiprocessing模块转自:http://blog.csdn.net/zhaozhi406/article/details/8137670 前言 这两天为了做一个小项目,研究了一下python的并发编程,所谓并发无非多线程……继续阅读 » 水墨上仙 5年前 (2021-03-05) 2239浏览 421个赞
Python中*args 和**kwargs的用法当函数的参数不确定时,可以使用*args 和**kwargs,*args 没有key值,**kwargs有key值。def fun_var_args(farg, *args): print "arg:", farg for value in args: ……继续阅读 » 水墨上仙 5年前 (2021-03-05) 2713浏览 2232个赞
python事件信号调度#idle_queue.pyimport Queue#Global queue, import it from anywhere, you get the same object instance.idle_loop = Queue.Queue()def idle_add(func, *args, **kwargs):……继续阅读 » 水墨上仙 5年前 (2021-03-05) 2067浏览 2627个赞
python下有个paramiko模块,这个模块可以实现ssh登录linux服务器,下面贴出代码,注意,我在centos5.6下,python2.6.5,paramiko-1.7的版本下测试成功。。。转自:http://world77.blog.51cto.com/414605/618425#!/usr/bin/env pythonimport……继续阅读 » 水墨上仙 5年前 (2021-03-05) 3164浏览 2375个赞
python ftplib模块制作ftp客户端转自:http://blog.csdn.net/xm1331305/article/details/8137638#!/usr/bin/python#-*- coding:utf-8 -*-from ftplib import FTP #加载ftp模块ftp=FTP() ……继续阅读 » 水墨上仙 5年前 (2021-03-05) 2624浏览 1863个赞
python实现选择排序算法def ssort(V): #V is the list to be sorted j = 0 #j is the "current" ordered position, start……继续阅读 » 水墨上仙 5年前 (2021-03-05) 2579浏览 2070个赞
python按字符翻转字符串 New in python 2.4:a_string = reversed(a_string) New i……继续阅读 » 水墨上仙 5年前 (2021-03-05) 2405浏览 519个赞
python清除字符串里的非数字字符import re s = "how19 a*re 254y**ou?" # Using regular expressions print re.sub("\D", "", s) ……继续阅读 » 水墨上仙 5年前 (2021-03-05) 3335浏览 410个赞
python四舍五入函数round的用法范例print round(3.4) # 3 print round(3.5) # 4 print round(3.6) # 4 print round(3.6, 0) # 4 print round(1.95583, 2) # 1.96……继续阅读 » 水墨上仙 5年前 (2021-03-05) 2853浏览 1161个赞
python在windows下创建隐藏窗口的子进程import subprocessIS_WIN32 = 'win32' in str(sys.platform).lower()def subprocess_call(*args, **kwargs): #also works for Popen. It creates ……继续阅读 » 水墨上仙 5年前 (2021-03-05) 3122浏览 1387个赞
python创建只包含指定扩展名文件的目录结构列表#!/usr/bin/python#===============================================================================# Creator: ACHAL RASTOGI# Dedicated to my Love: SHAL……继续阅读 » 水墨上仙 5年前 (2021-03-05) 2146浏览 2274个赞
Python删除指定目录下的过期文件import osimport sysimport timeclass DeleteLog: def __init__(self,fileName,days): self.fileName = fileName self.days = days def delet……继续阅读 » 水墨上仙 5年前 (2021-03-05) 1626浏览 1366个赞
python简单的计算过期时间的代码 def time_passed(value): now = datetime.now() past = now - value if past.days: return u'%s天前' % past.days mins = past.seconds……继续阅读 » 水墨上仙 5年前 (2021-03-05) 2275浏览 1688个赞
python操作sqlite3数据库完全代码# Name: pySnipnix.py# Author: pantuts# Email: pantuts@gmail.com# Description: Saving your snippets to sqlite3 database.# Agreement: You can use, modify……继续阅读 » 水墨上仙 5年前 (2021-03-05) 2574浏览 287个赞
C语言调用python代码来源:http://blog.csdn.net/agoago_2009/article/details/8003549//#========================================================//# author:ago ……继续阅读 » 水墨上仙 5年前 (2021-03-05) 3067浏览 1630个赞
用python实现希尔排序算法(shell sort)def shellSort(items): inc = len(items) / 2 while inc: for i in xrange(len(items)): j = i temp = items[i] ……继续阅读 » 水墨上仙 5年前 (2021-03-05) 1616浏览 2406个赞
python清除字符串里的非字母字符s = "hello world! how are you? 0" # Short version print filter(lambda c: c.isalpha(), s) # Faster version for long ASCII strings: id_ta……继续阅读 » 水墨上仙 5年前 (2021-03-05) 2087浏览 232个赞
本代码演示了python如何在二进制、十进制、十六进制之间相互转换的代码#!/usr/bin/env python# -*- coding: utf-8 -*-# 2/10/16 base trans. wrote by srcdog on 20th, April, 2009# ld elements in base 2, 10, 16.imp……继续阅读 » 水墨上仙 5年前 (2021-03-05) 2912浏览 990个赞
Sphinx的Python客户端示例# coding: utf-8 # sphinxapi.py 可见于 coreseek-4.1-win32\api\目录内 import sphinxapi import pprint spc = sphinxapi.SphinxClient() spc.SetServer('12……继续阅读 » 水墨上仙 5年前 (2021-03-05) 2325浏览 2671个赞
python各种删除空格的方法汇总,strip删除两个空格,lstrip删除左边的空格,rstrip删除右边的空格" xyz ".strip() # returns "xyz" " xyz ".lstrip() # returns ……继续阅读 » 水墨上仙 5年前 (2021-03-05) 1721浏览 2750个赞
在Python中的高斯 – 赛德尔方法Gauss-Seidel method in Python''' x,numIter,omega = gaussSeidel(iterEqs,x,tol = 1.0e-9) Gauss-Seidel method for solving [A]{x} = {b}.……继续阅读 » 水墨上仙 5年前 (2021-03-05) 3060浏览 2396个赞
Find the global bounds on the eigenvalues of a tridiagomal matrix in Python''' lamMin,lamMax = gerschgorin(d,c). Applies Gerschgorin's theorem to find the……继续阅读 » 水墨上仙 5年前 (2021-03-05) 2561浏览 236个赞
python中的黄金分割法''' a,b = bracket(f,xStart,h) Finds the brackets (a,b) of a minimum point of the user-supplied scalar function f(x). The search starts dow……继续阅读 » 水墨上仙 5年前 (2021-03-05) 2650浏览 2126个赞
Modified midpoint method for solving the initial value problem in Python''' yStop = integrate (F,x,y,xStop,tol=1.0e-6) Modified midpoint method for solving the……继续阅读 » 水墨上仙 5年前 (2021-03-05) 3371浏览 2533个赞
Gauss-Legendre integration in Python''' I = gaussQuad2(f,xc,yc,m). Gauss-Legendre integration of f(x,y) over a quadrilateral using integration order m. ……继续阅读 » 水墨上仙 5年前 (2021-03-05) 1593浏览 2911个赞
Python LU 分解LU decomposition in Python''' a = LUdecomp(a). LU decomposition: [L][U] = [a]. The returned matrix [a] = [L\U] contains [U] in the upper trian……继续阅读 » 水墨上仙 5年前 (2021-03-05) 3265浏览 215个赞
Householder similarity transformation of matrix in Python''' d,c = householder(a). Householder similarity transformation of matrix [a] to the tridiagonal ……继续阅读 » 水墨上仙 5年前 (2021-03-05) 2433浏览 1478个赞
在Python中的线性函数直线插补查找零Find the zero of the linear function straight line interpolation in Python''' root = linInterp(f,x1,x2). Finds the zero of the linear func……继续阅读 » 水墨上仙 5年前 (2021-03-05) 3195浏览 2533个赞
LU decomposition of symetric pentadiagonal matrix in Python''' d,e,f = LUdecomp5(d,e,f). LU decomposition of symetric pentadiagonal matrix [f\e\d\e\f]. On ……继续阅读 » 水墨上仙 5年前 (2021-03-05) 1474浏览 2640个赞
根据目录下的文件名生成SQL语句#!/usr/bin/python#coding=utf-8import osfrom datetime import datetimepath = "/Users/Demos/Desktop/ss/"id = 0#历遍指定文件夹for x in os.listdir(path):……继续阅读 » 水墨上仙 5年前 (2021-03-05) 2852浏览 2554个赞
python sqlite3的常规使用#Filename: DBcon.pyimport sqlite3import timeconn=sqlite3.connect(r'D:\Exercise\Python\DB\example.db')c=conn.cursor()c.execute("Create tab……继续阅读 » 水墨上仙 5年前 (2021-03-05) 2355浏览 371个赞
Python 调用 C++#include <boost/python.hpp> #include <boost/python/module.hpp> #include <boost/python/def.hpp> #include <boost/python/to_python_converter.hp……继续阅读 » 水墨上仙 5年前 (2021-03-05) 1485浏览 2214个赞
Python生成目录树# encoding: utf-8 import os class dir(object): def __init__(self): self.SPACE = "" self.list = [] def getC……继续阅读 » 水墨上仙 5年前 (2021-03-05) 2262浏览 2655个赞
子网掩码格式转换#!/usr/bin/env python#-*- coding:utf-8 -*-exchange_mask = lambda mask: sum(bin(int(i)).count('1') \ for i in mask.split(……继续阅读 » 水墨上仙 5年前 (2021-03-05) 2935浏览 1878个赞
Python 刷点击量import webbrowser as webimport reimport urllibimport timeimport osdef spider(url,urlpattern): urls=getURLs(url,urlpattern) for url in urls: visit……继续阅读 » 水墨上仙 5年前 (2021-03-05) 3427浏览 2470个赞
动态规划算法,计算单词距离#!/usr/bin/env python#coding=utf-8def word_distance(m,n): """compute the least steps number to convert m to n by insert , delete , replace . ……继续阅读 » 水墨上仙 5年前 (2021-03-05) 1885浏览 547个赞
Python 读取系统环境变量import osfilename = os.environ.get('PYTHONSTARTUP')if filename and os.path.isfile(filename): execfile(filename)……继续阅读 » 水墨上仙 5年前 (2021-03-05) 3310浏览 1416个赞
python转换字符集def URLtoUTF8(string): """""" g_code_type = ['utf-8', 'utf8', 'gb18030', 'gb2312', '……继续阅读 » 水墨上仙 5年前 (2021-03-05) 2866浏览 2592个赞
python分割文件#!/usr/bin/env pythondef split(filename, size): fp = open(filename, 'rb') i = 0 n = 0 temp = open(filename+'.part'+str(i),'w……继续阅读 » 水墨上仙 5年前 (2021-03-05) 1862浏览 928个赞
python scp备份文件#!/usr/bin/env pythonimport MySQLdbimport osimport pexpectdef conn_to_mysql(): """Make a Connection to the mysql server"""……继续阅读 » 水墨上仙 5年前 (2021-03-05) 2861浏览 727个赞
获取文件夹大小的python代码import osfrom os.path import join, getsizedef getdirsize(dir): size = 0L for root, dirs, files in os.walk(dir): size += sum([getsize(join(root, na……继续阅读 » 水墨上仙 5年前 (2021-03-05) 2392浏览 1858个赞
快速多线程ping#!/usr/bin/python#_*_coding:utf-8_*_#'''名称:快速多线程ping程序开发:gyhong gyh9711日期:20:51 2011-04-25'''import pexpectimport datetimefrom ……继续阅读 » 水墨上仙 5年前 (2021-03-05) 2700浏览 2175个赞
python file_name_of_this_app.py http://www.ijingxuan.com/#!/usr/bin/env python# -*- coding: utf-8 -*-# ***********************************************************************……继续阅读 » 水墨上仙 5年前 (2021-03-05) 2101浏览 829个赞