python 中map函数使用范例代码# build a dictionary that maps the ordinals from 32 to 255# to their ASCII character equivalents eg. 33: '!'# (note that 32 and 160 are spaces)……继续阅读 » 水墨上仙 6年前 (2019-09-03) 2387浏览 2083个赞
python统计文本文件内单词数量# count lines, sentences, and words of a text file# set all the counters to zerolines, blanklines, sentences, words = 0, 0, 0, 0print '-' * 50tr……继续阅读 » 水墨上仙 6年前 (2019-09-03) 2523浏览 171个赞
Go语言获取数组长度// getting the length of an array is silly, because the length is part of the array's static typemyArray := [3]int{1, 2, 3}fmt.Println(len(myArray)) // prints 3……继续阅读 » 水墨上仙 6年前 (2019-09-03) 3123浏览 2455个赞
创建游戏$ cocos new -p com.yt.supermario -d ~/yt/game/ -l cpp supermario> 拷贝模板到 /Users/yt/yt/game/supermario> 拷贝 cocos2d-x ...> 替换文件名中的工程名称,'HelloCpp' 替换为 &……继续阅读 » 开心洋葱 6年前 (2019-09-03) 1988浏览 0评论2835个赞
Go语言排序与接口代码演示import "fmt"type Sorter interface { Len() int Less(i, j int) bool Swap(i, j int)}type Xi []inttype Xs []stringfunc (p Xi) Len() int { ……继续阅读 » 水墨上仙 6年前 (2019-09-03) 3114浏览 659个赞
Go语言写入字符串到文件代码package main import "fmt"import "os"func main() { fileName := "test.dat" dstFile,err := os.Create(fileName) if err!=nil……继续阅读 » 水墨上仙 6年前 (2019-09-03) 1547浏览 2348个赞
go语言里使用scp的范例// https://blogs.oracle.com/janp/entry/how_the_scp_protocol_workspackage mainimport ( "code.google.com/p/go.crypto/ssh" "crypto" &q……继续阅读 » 水墨上仙 6年前 (2019-09-03) 2264浏览 720个赞
本范例演示了JS中如何通过String.prototype自定义字符串操作协议,本代码定义了两个操作方法,一个用于清除html标签,一个用来转换html标签,都非常有用String.prototype.stripslashes = function(){ return this.replace(/<.*?>/g, '……继续阅读 » 水墨上仙 6年前 (2019-09-03) 1838浏览 1326个赞
实现示例:sql: state=11 and (aa=2 or bb=3)mongodb: { state : “11” , $or : [ { aa : 2 } , { bb : 3 } ] }BasicDBObject whereEnd = new BasicDBObject();whereEnd.put(“s……继续阅读 » 开心洋葱 6年前 (2019-08-22) 2058浏览 0评论2746个赞
angular8 添加 消息弹窗提示错误There is no directive with “exportAs” set to “bs-modal” Uncaught Error: Template parse errors:There is no directive with “export……继续阅读 » 开心洋葱 6年前 (2019-08-15) 3142浏览 0评论2453个赞
start.spring.io替换国内地址start.75271.com解决spring boot start.spring.io 不能访问使用http://start.spring.io/ 生成工程目前不能访问,可以访问国内地址http://start.75271.comstart.spring.io 访问不了怎么办?这个可以这么解决Spring……继续阅读 » 开心洋葱 6年前 (2019-08-09) 2933浏览 0评论825个赞
import org.apache.commons.codec.binary.Base64; public class c { public static void main(String[] args) throws Exception { // String base64Str = // &quo……继续阅读 » 开心洋葱 6年前 (2019-08-08) 2041浏览 0评论2670个赞
python计算数组、元祖等列表元素的和print( sum([1,2,3])) 返回值:6……继续阅读 » 水墨上仙 6年前 (2019-08-08) 1510浏览 183个赞
python遍历字符串中的字符word = raw_input("Enter a word: ")print "\nHere's each letter in your word:"for letter in word: print letter……继续阅读 » 水墨上仙 6年前 (2019-08-08) 2126浏览 1879个赞
def isAString(anobj):return isinstance(anobj, basestring)def isAString(anobj): return isinstance(anobj, basestring)……继续阅读 » 水墨上仙 6年前 (2019-08-08) 3043浏览 351个赞
multipart/form-data类型的POST实体结构相对来说(常规的POST正文采用application/x-www-form-urlencoded格式)比较复杂,它常用于文件上传。下面是一个multipart/form-data格式的POST实体示例-----------------------------114782935826962 ……继续阅读 » 水墨上仙 6年前 (2019-08-08) 2370浏览 1318个赞
python写日志的封装类# encoding:utf-8import sysimport loggingimport time def writeLog(message): logger=logging.getLogger() filename = time.strftime('%Y-%m-%d'……继续阅读 » 水墨上仙 6年前 (2019-08-08) 2269浏览 479个赞
python链接Oracle数据库的代码,需要引用cx_Oracle库#coding=UTF-8 import cx_Oracle def hello(): '''Hello cx_Oracle示例: 1)打印数据库版本信息. 2)查询表数据.'……继续阅读 » 水墨上仙 6年前 (2019-08-08) 1721浏览 1756个赞
python 给目录下的图片批量加水印water.py 放到 图片文件夹里 然后cd 到当前文件夹 python water.py#coding=utf-8import Imageimport os#print list[0]#exit()def getlogo(x1,y1): im =Image.open("./&qu……继续阅读 » 水墨上仙 6年前 (2019-08-08) 2091浏览 1925个赞
python正则查找所有匹配的字符串import re p = re.compile(r'\d+')print p.findall('one1two2three3four4') ### output #### ['1', '2', '3……继续阅读 » 水墨上仙 6年前 (2019-08-08) 3503浏览 1768个赞
python zip和unzip数据# zipping and unzipping a string using the zlib module# a very large string could be zipped and saved to a file speeding up file writing time # and later rel……继续阅读 » 水墨上仙 6年前 (2019-08-08) 1491浏览 2689个赞
wxpython GUI界面显示jpg图片# show a jpeg (.jpg) image using wxPython, newer coding style# two different ways to load and display are given# tested with Python24 and wxPython25 veg……继续阅读 » 水墨上仙 6年前 (2019-08-08) 2855浏览 1281个赞
python将文本转换成语音# Text To Speech using SAPI (Windows) and Python module pyTTS by Peter Parente# download installer file pyTTS-3.0.win32-py2.4.exe # from: http://sourceforge.ne……继续阅读 » 水墨上仙 6年前 (2019-08-08) 2750浏览 233个赞
由于Python设计的限制(我说的是咱们常用的CPython)。最多只能用满1个CPU核心。Python提供了非常好用的多进程包multiprocessing,你只需要定义一个函数,Python会替你完成其他所有事情。借助这个包,可以轻松完成从单进程到并发执行的转换。1、新建单一进程如果我们新建少量进程,可以如下:import multiproces……继续阅读 » 水墨上仙 6年前 (2019-08-08) 1293浏览 1884个赞
在2.6才开始使用multiprocessing 是一个使用方法类似threading模块的进程模块。允许程序员做并行开发。并且可以在UNIX和Windows下运行。通过创建一个Process 类型并且通过调用call()方法spawn一个进程。下面是该模块的一个测试程序。效果非常好#!/usr/bin/env python#coding=utf-……继续阅读 » 水墨上仙 6年前 (2019-08-08) 1530浏览 2744个赞
python subprocess模块 监控子进程的2种方式 忙等待和立即返回同时设置子进程超时时间一:循环 忙等 子进程结束import subprocess import os import time tt = '555' cmd = "python /home/1……继续阅读 » 水墨上仙 6年前 (2019-08-08) 2696浏览 2505个赞
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) 2469浏览 1068个赞
Advanced Python Scheduler是一个python的定时执行任务的框架,调用无比简单,不用自己写定时器了 演示代码from apscheduler.scheduler import Schedulersched = Scheduler()@sched.i……继续阅读 » 水墨上仙 6年前 (2019-08-08) 2201浏览 825个赞
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) 1536浏览 883个赞
python通过xmlrpc进行远程调用的范例演示服务器端代码# -*- coding: utf-8 -*-import SimpleXMLRPCServer#server 上面的程式碼 def Show_me_some_message(sMsg):#從遠端呼叫並且帶入參數 print "I see your call……继续阅读 » 水墨上仙 6年前 (2019-08-08) 3008浏览 2092个赞
Go语言的string模块包含了ToLower和ToUpper函数,用于将字符串转换成小写和大写package mainimport ( "fmt" "strings")func main() { fmt.Println(strings.ToUpper("hello wo……继续阅读 » 水墨上仙 6年前 (2019-08-08) 1724浏览 1804个赞
select 语句使得一个 goroutine 在多个通讯操作上等待。select 会阻塞,直到条件分支中的某个可以继续执行,这时就会执行那个条件分支。当多个都准备好的时候,会随机选择一个。package mainimport "fmt"func fibonacci(c, quit chan int) { ……继续阅读 » 水墨上仙 6年前 (2019-08-08) 1607浏览 2246个赞
通过两种方式提供基于HTML模板的多变量值替换。另外附加一个数组迭代的示例。 传入map实现多值替换package mainimport ( "html/template" "os")func main() { t,……继续阅读 » 水墨上仙 6年前 (2019-08-08) 2450浏览 1861个赞
JavaScript转向跳转(redirect)<script type="text/javascript"><!-- window.location = "http://www.google.com/" //--></script> ……继续阅读 » 水墨上仙 6年前 (2019-08-08) 1366浏览 1254个赞
一个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) 1797浏览 770个赞
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) 3223浏览 1670个赞
python rpc twisted 服务端和客户端代码演示#服务器端代码如下from twisted.web import xmlrpc, serverclass Example(xmlrpc.XMLRPC): """ An example object to be published. ……继续阅读 » 水墨上仙 6年前 (2019-08-03) 2151浏览 1942个赞
wxpython自定义语法高亮控件,支持python语法高亮,只需要稍加修改就可以支持其它语言的语法高亮import keywordimport wximport wx.stc as stcimport images#--------------------------------------------------------……继续阅读 » 水墨上仙 6年前 (2019-08-03) 1937浏览 355个赞
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) 2516浏览 2657个赞
Go语言计算指定年月的天数package mainimport ( "fmt" "bufio" "os" "regexp" "strconv")func main() { year := input("year&……继续阅读 » 水墨上仙 6年前 (2019-08-03) 2360浏览 2106个赞
在JavaScript里乘法比除法的性能要好得多,所以同样的程序如果能用乘法就不用除法//除法,慢var my_variable = 5 / 2;//乘法,快var my_variable = 5 * 0.5; ……继续阅读 » 水墨上仙 6年前 (2019-08-03) 3383浏览 567个赞
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) 2619浏览 2603个赞
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) 1217浏览 1197个赞
python读写ini配置文件import ConfigParserimport osclass ReadWriteConfFile: currentDir=os.path.dirname(__file__) filepath=currentDir+os.path.sep+"inetMsgConfigure.ini&……继续阅读 » 水墨上仙 6年前 (2019-08-02) 1630浏览 2340个赞
设有一个m×n的棋盘(2≤m≤50,2≤n≤50),在棋盘上任一点有一个中国象棋“马”,马走的规则为:马走日字;马只能向右走。当m,n给出后,同时给出马起始的位置和终点的位置,试找出从起点到终点所有路径的数目。输入:    m,n,x1,y1,x2,y2 (分别表示m,n、起点……继续阅读 » 水墨上仙 6年前 (2019-08-02) 2194浏览 336个赞