本代码演示了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……继续阅读 » 水墨上仙 4年前 (2021-03-05) 1818浏览 1485个赞
Sphinx的Python客户端示例# coding: utf-8 # sphinxapi.py 可见于 coreseek-4.1-win32\api\目录内 import sphinxapi import pprint spc = sphinxapi.SphinxClient() spc.SetServer('12……继续阅读 » 水墨上仙 4年前 (2021-03-05) 2574浏览 2455个赞
python各种删除空格的方法汇总,strip删除两个空格,lstrip删除左边的空格,rstrip删除右边的空格" xyz ".strip() # returns "xyz" " xyz ".lstrip() # returns ……继续阅读 » 水墨上仙 4年前 (2021-03-05) 2438浏览 636个赞
在Python中的高斯 – 赛德尔方法Gauss-Seidel method in Python''' x,numIter,omega = gaussSeidel(iterEqs,x,tol = 1.0e-9) Gauss-Seidel method for solving [A]{x} = {b}.……继续阅读 » 水墨上仙 4年前 (2021-03-05) 1480浏览 120个赞
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……继续阅读 » 水墨上仙 4年前 (2021-03-05) 2899浏览 2707个赞
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……继续阅读 » 水墨上仙 4年前 (2021-03-05) 1273浏览 2188个赞
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……继续阅读 » 水墨上仙 4年前 (2021-03-05) 1383浏览 1731个赞
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. ……继续阅读 » 水墨上仙 4年前 (2021-03-05) 1758浏览 1554个赞
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……继续阅读 » 水墨上仙 4年前 (2021-03-05) 2359浏览 2057个赞
Householder similarity transformation of matrix in Python''' d,c = householder(a). Householder similarity transformation of matrix [a] to the tridiagonal ……继续阅读 » 水墨上仙 4年前 (2021-03-05) 2953浏览 111个赞
在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……继续阅读 » 水墨上仙 4年前 (2021-03-05) 3149浏览 1469个赞
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 ……继续阅读 » 水墨上仙 4年前 (2021-03-05) 2761浏览 950个赞
根据目录下的文件名生成SQL语句#!/usr/bin/python#coding=utf-8import osfrom datetime import datetimepath = "/Users/Demos/Desktop/ss/"id = 0#历遍指定文件夹for x in os.listdir(path):……继续阅读 » 水墨上仙 4年前 (2021-03-05) 2012浏览 2859个赞
python sqlite3的常规使用#Filename: DBcon.pyimport sqlite3import timeconn=sqlite3.connect(r'D:\Exercise\Python\DB\example.db')c=conn.cursor()c.execute("Create tab……继续阅读 » 水墨上仙 4年前 (2021-03-05) 2167浏览 1661个赞
Python 调用 C++#include <boost/python.hpp> #include <boost/python/module.hpp> #include <boost/python/def.hpp> #include <boost/python/to_python_converter.hp……继续阅读 » 水墨上仙 4年前 (2021-03-05) 2877浏览 2464个赞
Python生成目录树# encoding: utf-8 import os class dir(object): def __init__(self): self.SPACE = "" self.list = [] def getC……继续阅读 » 水墨上仙 4年前 (2021-03-05) 1871浏览 2965个赞
子网掩码格式转换#!/usr/bin/env python#-*- coding:utf-8 -*-exchange_mask = lambda mask: sum(bin(int(i)).count('1') \ for i in mask.split(……继续阅读 » 水墨上仙 4年前 (2021-03-05) 2630浏览 2701个赞
Python 刷点击量import webbrowser as webimport reimport urllibimport timeimport osdef spider(url,urlpattern): urls=getURLs(url,urlpattern) for url in urls: visit……继续阅读 » 水墨上仙 4年前 (2021-03-05) 3091浏览 2367个赞
动态规划算法,计算单词距离#!/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 . ……继续阅读 » 水墨上仙 4年前 (2021-03-05) 2092浏览 1706个赞
Python 读取系统环境变量import osfilename = os.environ.get('PYTHONSTARTUP')if filename and os.path.isfile(filename): execfile(filename)……继续阅读 » 水墨上仙 4年前 (2021-03-05) 1523浏览 314个赞
python转换字符集def URLtoUTF8(string): """""" g_code_type = ['utf-8', 'utf8', 'gb18030', 'gb2312', '……继续阅读 » 水墨上仙 4年前 (2021-03-05) 2885浏览 2616个赞
python分割文件#!/usr/bin/env pythondef split(filename, size): fp = open(filename, 'rb') i = 0 n = 0 temp = open(filename+'.part'+str(i),'w……继续阅读 » 水墨上仙 4年前 (2021-03-05) 3180浏览 1160个赞
python scp备份文件#!/usr/bin/env pythonimport MySQLdbimport osimport pexpectdef conn_to_mysql(): """Make a Connection to the mysql server"""……继续阅读 » 水墨上仙 4年前 (2021-03-05) 2503浏览 2257个赞
获取文件夹大小的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……继续阅读 » 水墨上仙 4年前 (2021-03-05) 1784浏览 646个赞
快速多线程ping#!/usr/bin/python#_*_coding:utf-8_*_#'''名称:快速多线程ping程序开发:gyhong gyh9711日期:20:51 2011-04-25'''import pexpectimport datetimefrom ……继续阅读 » 水墨上仙 4年前 (2021-03-05) 1433浏览 1140个赞
python file_name_of_this_app.py http://www.ijingxuan.com/#!/usr/bin/env python# -*- coding: utf-8 -*-# ***********************************************************************……继续阅读 » 水墨上仙 4年前 (2021-03-05) 2673浏览 2562个赞
python通过collections解决约瑟夫问题据说著名犹太历史学家 Josephus有过以下的故事:在罗马人占领乔塔帕特后,39 个犹太人与Josephus及他的朋友躲到一个洞中,39个犹太人决定宁愿死也不要被敌人抓到,于是决定了一个自杀方式,41个人排成一个圆圈,由第1个人开始报数,每报数到第3人该人就必须自杀,然后再由下一个重新报数,直到所有人都自……继续阅读 » 水墨上仙 4年前 (2021-03-05) 2581浏览 2348个赞
来源:http://stackoverflow.com/questions/3806562/ways-to-move-up-and-down-the-dir-structure-in-python#Moving up/down dir structureprint os.listdir('.') # current levelpr……继续阅读 » 水墨上仙 4年前 (2021-03-05) 2580浏览 534个赞
python超简代码解决约瑟夫环问题 约瑟环问题大家都熟悉。题目是这样的。一共有三十个人,从1-30依次编号。每次隔9个人就踢出去一个人。求踢出的前十五个人的号码。转自:http://blog.sina.com.cn/s/blog_9e11a7b40101dlzz.htmla = [ x for x in range(1,31) ] #生成编号de……继续阅读 » 水墨上仙 4年前 (2021-03-05) 2893浏览 266个赞
python返回昨天的日期 #-*-coding:utf-8-*- import datetimedef getYesterday(): # today=datetime.date.today() oneday=datetime.timedelta(days=1) yesterday=today-oneday ……继续阅读 » 水墨上仙 4年前 (2021-03-05) 2659浏览 769个赞
python计算两个日期相差的天数#两个日期相隔多少天,例:2008-10-03和2008-10-01是相隔两天 def datediff(beginDate,endDate): format="%Y-%m-%d"; bd=strtodatetime(beginDate,format) ed=s……继续阅读 » 水墨上仙 4年前 (2021-03-05) 1754浏览 2837个赞
Evaluate X and Y returned from the differential equation solvers using printput frequency in Python''' printSoln(X,Y,freq). Prints X and Y returned from the di……继续阅读 » 水墨上仙 4年前 (2021-03-05) 1267浏览 2298个赞
Python example of using Laguerre’s method to compute all the roots of equation''' roots = polyRoots(a). Uses Laguerre's method to compute all the roots of……继续阅读 » 水墨上仙 4年前 (2021-03-05) 2266浏览 1471个赞
Powell’s method of minimizing user-supplied function in Python''' xMin,nCyc = powell(F,x,h=0.1,tol=1.0e-6) Powell's method of minimizing user-supplied fun……继续阅读 » 水墨上仙 4年前 (2021-03-05) 2819浏览 1986个赞
Plots data points and the fitting polynomial using Python''' plotPoly(xData,yData,coeff) Plots data points and the fitting polynomial defined by its coeffi……继续阅读 » 水墨上仙 4年前 (2021-03-05) 2963浏览 481个赞
Solve simultaneous equations using the Newton-Raphson method in Python''' soln = newtonRaphson2(f,x,tol=1.0e-9). Solves the simultaneous equations f(x) = 0 by……继续阅读 » 水墨上仙 4年前 (2021-03-05) 2410浏览 752个赞
在python中使用tempconv模块转换问题from tempconv import ctoffrom tempconv import ftoc temp = 95convTemp = ftoc(temp)print("the converted temp is " + str(convTemp))temp = 0c……继续阅读 » 水墨上仙 4年前 (2021-03-05) 2243浏览 1212个赞
python计算指定多少天后的日期,python做日期增减是相当简单的 d1 = datetime.datetime.now()d3 = d1 + datetime.timedelta(days =10)print d3.ctime()……继续阅读 » 水墨上仙 4年前 (2021-03-05) 1558浏览 2596个赞
python中if elif条件语句实用范例marks = 99if marks >= 90: grade = 'A'elif marks >= 80: grade = 'B'elif marks >= 70: grade = 'C'elif mark……继续阅读 » 水墨上仙 4年前 (2021-03-05) 1741浏览 1048个赞
python计算对角线有理函数插值''' p = rational(xData,yData,x) Evaluates the diagonal rational function interpolant p(x) that passes through he data points''&……继续阅读 » 水墨上仙 4年前 (2021-03-05) 1814浏览 2151个赞
Python查找函数f(x)=0的根的代码''' root = ridder(f,a,b,tol=1.0e-9). Finds a root of f(x) = 0 with Ridder's method. The root must be bracketed in (a,b).'……继续阅读 » 水墨上仙 4年前 (2021-03-05) 3029浏览 2218个赞
python通过range函数计算一组数的和sum = 0numbers = range(1,10)for i in numbers: sum += iprint(sum)……继续阅读 » 水墨上仙 4年前 (2021-03-05) 2305浏览 1856个赞
python中localtime和gtime的区别及时区计算 localtime和gtime的区别:import timenow = time.time()time.localtime() (2007,……继续阅读 » 水墨上仙 4年前 (2021-03-05) 1439浏览 486个赞
python中使用sharp模块的简单范例from shapes import Shapefrom shapes import Rectangle s1 = Shape(2,4)print(s1)r1 = Rectangle(4,8,3,5)print(r1)……继续阅读 » 水墨上仙 4年前 (2021-03-05) 2569浏览 1387个赞
python中while循环语句的简单实用范例number = 1while number < 20: print(number) number += 1……继续阅读 » 水墨上仙 4年前 (2021-03-05) 2988浏览 330个赞