python插入排序示范代码(算法)插入排序就是每一步都将一个待排数据按其大小插入到已经排序的数据中的适当位置,直到全部插入完毕. 数据演示:[1,4,2,3]第一次:[1,4,2,3]第二次:[1,4,2,3]第三次:[1,2,4,3]第四次:[1,2,3,4]代码示例如下:……继续阅读 » 6年前 (2019-08-08) 1669浏览 481个赞
Advanced Python Scheduler是一个python的定时执行任务的框架,调用无比简单,不用自己写定时器了 演示代码from apscheduler.scheduler import Schedulersched = Scheduler()@sched.i……继续阅读 » 6年前 (2019-08-08) 1814浏览 1918个赞
python重命名文件代码#-*-coding:gbk-*-import oscur_path = os.getcwd()lists = os.listdir( cur_path )for f in lists: if f != 'ren.py': print cur_path ……继续阅读 » 6年前 (2019-08-08) 2569浏览 2611个赞
python通过xmlrpc进行远程调用的范例演示服务器端代码# -*- coding: utf-8 -*-import SimpleXMLRPCServer#server 上面的程式碼 def Show_me_some_message(sMsg):#從遠端呼叫並且帶入參數 print "I see your call……继续阅读 » 6年前 (2019-08-08) 2422浏览 500个赞
Go语言的string模块包含了ToLower和ToUpper函数,用于将字符串转换成小写和大写package mainimport ( "fmt" "strings")func main() { fmt.Println(strings.ToUpper("hello wo……继续阅读 » 6年前 (2019-08-08) 1476浏览 2491个赞
select 语句使得一个 goroutine 在多个通讯操作上等待。select 会阻塞,直到条件分支中的某个可以继续执行,这时就会执行那个条件分支。当多个都准备好的时候,会随机选择一个。package mainimport "fmt"func fibonacci(c, quit chan int) { ……继续阅读 » 6年前 (2019-08-08) 2548浏览 962个赞
通过两种方式提供基于HTML模板的多变量值替换。另外附加一个数组迭代的示例。 传入map实现多值替换package mainimport ( "html/template" "os")func main() { t,……继续阅读 » 6年前 (2019-08-08) 2429浏览 2409个赞
JavaScript转向跳转(redirect)<script type="text/javascript"><!-- window.location = "http://www.google.com/" //--></script> ……继续阅读 » 6年前 (2019-08-08) 2787浏览 2858个赞
一个Python编写的简单hangman游戏代码#!/usr/bin/env pythonimport random import cPickle class Hangman(object): '''A simple hangman game that tries to improve your voca……继续阅读 » 6年前 (2019-08-03) 3114浏览 2780个赞
python执行子进程 进程间通信a.pyimport subprocess, timesubproc = subprocess.Popen(['c:\python31\python.exe', 'c:/b.py'], stdin=subprocess.PIPE, shell=True) time.sl……继续阅读 » 6年前 (2019-08-03) 1960浏览 700个赞
python rpc twisted 服务端和客户端代码演示#服务器端代码如下from twisted.web import xmlrpc, serverclass Example(xmlrpc.XMLRPC): """ An example object to be published. ……继续阅读 » 6年前 (2019-08-03) 3174浏览 1231个赞
wxpython自定义语法高亮控件,支持python语法高亮,只需要稍加修改就可以支持其它语言的语法高亮import keywordimport wximport wx.stc as stcimport images#--------------------------------------------------------……继续阅读 » 6年前 (2019-08-03) 2398浏览 1486个赞
Go语言实现冒泡法排序算法代码package mainimport "fmt"func main() { arr := []int{4,5,3,29,9} for i:=0;i<len(arr);i++{ for j:=i+1;j<len(arr);j++{ if arr[j] < arr……继续阅读 » 6年前 (2019-08-03) 2321浏览 905个赞
Go语言计算指定年月的天数package mainimport ( "fmt" "bufio" "os" "regexp" "strconv")func main() { year := input("year&……继续阅读 » 6年前 (2019-08-03) 1311浏览 958个赞
在JavaScript里乘法比除法的性能要好得多,所以同样的程序如果能用乘法就不用除法//除法,慢var my_variable = 5 / 2;//乘法,快var my_variable = 5 * 0.5; ……继续阅读 » 6年前 (2019-08-03) 3212浏览 1631个赞
Pascal求N以内的完美数完全数(Perfect number),又称完美数或完备数,是一些特殊的自然数。它所有的真因子(即除了自身以外的约数)的和(即因子函数),恰好等于它本身。program bill02;var m,n,y,i,j,s,ss,z:longint;a:array[1..10000] of integer;beginre……继续阅读 » 6年前 (2019-08-02) 2052浏览 2563个赞
python集合使用范例# sets are unordered collections of unique hashable elements# Python23 tested vegaseat 09mar2005# Python v2.4 has sets built inimport setsprint "……继续阅读 » 6年前 (2019-08-02) 2238浏览 845个赞
python读写ini配置文件import ConfigParserimport osclass ReadWriteConfFile: currentDir=os.path.dirname(__file__) filepath=currentDir+os.path.sep+"inetMsgConfigure.ini&……继续阅读 » 6年前 (2019-08-02) 2125浏览 594个赞
设有一个m×n的棋盘(2≤m≤50,2≤n≤50),在棋盘上任一点有一个中国象棋“马”,马走的规则为:马走日字;马只能向右走。当m,n给出后,同时给出马起始的位置和终点的位置,试找出从起点到终点所有路径的数目。输入:    m,n,x1,y1,x2,y2 (分别表示m,n、起点……继续阅读 » 6年前 (2019-08-02) 2005浏览 1117个赞
最近在做SEO的时候,为了让发的外链能够快速的收录,想到了利用ping的功能,google和百度都有相关的ping介绍,有兴趣的朋友可以去看看相关的知识。实现ping功能除了可以用一些开源的博客程序,比如WP,它是可以在后台设置ping地址的,只要设置好以后,你发帖子,就会自动的通知搜索引擎,我的博客已经更新了,而今天我用的方法是不通过WP等带有ping功能……继续阅读 » 6年前 (2019-08-02) 1180浏览 2283个赞
python通过tarfile模块压缩文件夹import tarfileimport osimport sysuser = os.getenv('USERNAME')filename = '/home/%s/tmp.tgz' % userprint 'The tar file was ……继续阅读 » 6年前 (2019-08-02) 1187浏览 1402个赞
Windows下批处理返回今天是星期几保存下面的代码为:test.bat,执行后返回:It’s 周六 today@ECHO OFFFOR /F "tokens=*" %%A IN ('DATE/T') DO FOR %%B IN (%%A) DO SET Today=%%BECHO It'……继续阅读 » 6年前 (2019-08-02) 2716浏览 1522个赞
如果用户访问http://地址,这段代码可以将用户自动转向https://地址window.location = "https://" + window.location.hostname + window.location.pathname + window.location.search; ……继续阅读 » 6年前 (2019-08-02) 2744浏览 724个赞
java实现逆波兰表达式算法import java.util.ArrayList;import java.util.List;public class MyStack { private List l; private int size; public String top; public MyStack() { l ……继续阅读 » 6年前 (2019-08-02) 1778浏览 1641个赞
Windows下批处理bat返回当前时间下面的代码可以返回系统当前时间:It’s 20:53:28.28 nowFOR %%A IN (%Date%) DO SET Today=%%ASET Now=%Time%ECHO It's %Today% todayECHO It's %Now% now……继续阅读 » 6年前 (2019-08-02) 2209浏览 2273个赞
django中是不能直接调用函数的,可以通过自定义filter来实现#template_filters.py@register.filterdef template_args(instance, arg): """ stores the arguments in a separate insta……继续阅读 » 6年前 (2019-08-02) 1278浏览 2444个赞
Java导出数据到Excel文件需要的jar包:easypoi-0.1.3.jar, poi-3.7-20101029package com.sais.inkaNet.reportStatistics.operationBeanavior.service;import java.io.IOException;import java.io.Outpu……继续阅读 » 6年前 (2019-08-02) 2330浏览 305个赞
JavaScript一行代码清除html标签var StrippedString = OriginalString.replace(/(<([^>]+)>)/ig,""); ……继续阅读 » 6年前 (2019-08-02) 3683浏览 2898个赞
// Define the XML DocumentNSXMLDocument* doc = [[NSXMLDocument alloc] initWithXMLString:[NSString stringWithContentsOfFile:@"/folder/with/sample.xml"]]; // C……继续阅读 » 6年前 (2019-08-02) 1749浏览 1175个赞
python 创建gtk应用程序,需要安装gtk包#!/usr/bin/env python## [代码名字: Create an Application Indicator]# [代码分类: Application Indicator]# [代码描述: How to create an application indicator and ad……继续阅读 » 6年前 (2019-07-11) 1724浏览 1335个赞
python在当前文件夹下设置一个简单的http服务器,执行后可以直接访问:http://127.0.0.1:8000就可以看到当前文件夹下的文件列表python -m SimpleHTTPServer……继续阅读 » 6年前 (2019-07-11) 2105浏览 2156个赞
有两个数组,它们长度相同,你希望把两个数组合并成一个字典,第一个数组的作为键,第二个数组作为值,python都可以很简单的帮你实现keys = [1, 2, 3, 4]values = [55, 56, 57, 58] new_dict = dict(zip(keys, values))……继续阅读 » 6年前 (2019-07-11) 2355浏览 2479个赞
我们知道python里没有switch语句,只能用多个if语句来实现,但python的字典却是万能的,下面的代码用字典实现了类似switch的功能try: sql_type = { 'STRING': 'TEXT', 'DOUBLE': 'NU……继续阅读 » 6年前 (2019-07-11) 2256浏览 1377个赞
python计算代码执行时间import time start = time.time() '''code you want to time goes here''' end = time.time()elapsed = end - startprint "Time ……继续阅读 » 6年前 (2019-07-11) 1993浏览 841个赞
当你在函数定义内声明变量的时候,它们与函数外具有相同名称的其他变量没有任何关系,即变量名称对于函数来说是 局部 的。这称为变量的 作用域 。所有变量的作用域是它们被定义的块,从它们的名称被定义的那点开始。#!/usr/bin/python# Filename: func_local.pydef func(x): print 'x ……继续阅读 » 6年前 (2019-07-11) 1862浏览 2244个赞
一段用来判断图片是否是色情图片的python代码,安装了pil包既可以使用转自:http://blog.csdn.net/lanphadayimport sys, Image pic = '2.jpg'img = Image.open(pic).convert('YCbCr') w, h = img.……继续阅读 » 6年前 (2019-07-11) 2769浏览 1704个赞
子类化wxPython application类class MyApp(wx.App): def OnInit(self): frame = wx.Frame(parent=None, id=-1, title=”Bare”) frame.Show() return True……继续阅读 » 6年前 (2019-07-11) 1559浏览 2554个赞
python链接字符串的几种方法 方法1:直接通过加号操作符相加foobar = ‘foo’ + ‘bar’ 方法2:join方法list_of_strings = ['abc', &……继续阅读 » 6年前 (2019-07-11) 2211浏览 2490个赞
python添加字符到文件代码with open("filename","a") as out: out.write("aString") ……继续阅读 » 6年前 (2019-07-11) 1763浏览 2269个赞
python中id()函数的实用研究实例>>> a = 2.5 >>> b = 2.5 >>> c = b >>> a is c 输出:False >>> a ……继续阅读 » 6年前 (2019-07-11) 1986浏览 2505个赞
在编码,解码过程中,会出现某些字符始终无法处理,此时该字符出现在(‘[\\x00-\\x08\\x0b-\\x0c\\x0e-\\x1f]’)范围值呢,去掉这些字符即可顺利编码,import re s = re.compile('[\\x00-\\x08\\x0b-\\x0c\\x0e-\\x1f]').s……继续阅读 » 6年前 (2019-07-11) 3143浏览 2305个赞
一个python高强度密码生成器,可以指定要生成的密码长度from os import urandomfrom random import choicechar_set = {'small': 'abcdefghijklmnopqrstuvwxyz', 'nums'……继续阅读 » 6年前 (2019-07-11) 1755浏览 122个赞
下面的代码可以从网络读取一张图片,不需要保存为本地文件,直接通过Image模块对图片进行处理,这里使用到了cStringIO库,主要是把从网络读取到的图片数据模拟成本地文件。import urllib2import Imageimport cStringIOdef ImageScale(url,size): file = cStringI……继续阅读 » 6年前 (2019-07-11) 1795浏览 1914个赞
用python来清除字符串里的html标签>>> print stripTags(‘Hello, world !‘)Hello, world !def stripTags(s): ''' Strips HTML tags. Taken from http://aspn……继续阅读 » 6年前 (2019-07-11) 1293浏览 531个赞
范例:[sectionA]var1=totovar2=titihomer=simpson[sectionB]var3=kikivar4=rorojohn=doe通过下面的代码读取后,返回结果如下:In section sectionB Key john has value doe Key var3 has value kiki Key var4 has……继续阅读 » 6年前 (2019-07-11) 2223浏览 2520个赞