python提供了非常方便的日志模块#-*- coding:utf-8 -*-import logging# 配置日志信息logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(name)-12s %(levelname)-……继续阅读 » 水墨上仙 6年前 (2019-09-03) 3241浏览 1190个赞
split(string[, maxsplit]) | re.split(pattern, string[, maxsplit]):按照能够匹配的子串将string分割后返回列表。maxsplit用于指定最大分割次数,不指定将全部分割。import re p = re.compile(r'\d+')print p.spli……继续阅读 » 水墨上仙 6年前 (2019-09-03) 2845浏览 2096个赞
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) 3091浏览 2035个赞
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) 3075浏览 2215个赞
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) 2580浏览 2146个赞
创建游戏$ cocos new -p com.yt.supermario -d ~/yt/game/ -l cpp supermario> 拷贝模板到 /Users/yt/yt/game/supermario> 拷贝 cocos2d-x ...> 替换文件名中的工程名称,'HelloCpp' 替换为 &……继续阅读 » 开心洋葱 6年前 (2019-09-03) 2182浏览 0评论854个赞
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) 2946浏览 454个赞
Go语言写入字符串到文件代码package main import "fmt"import "os"func main() { fileName := "test.dat" dstFile,err := os.Create(fileName) if err!=nil……继续阅读 » 水墨上仙 6年前 (2019-09-03) 1355浏览 358个赞
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) 1623浏览 668个赞
本范例演示了JS中如何通过String.prototype自定义字符串操作协议,本代码定义了两个操作方法,一个用于清除html标签,一个用来转换html标签,都非常有用String.prototype.stripslashes = function(){ return this.replace(/<.*?>/g, '……继续阅读 » 水墨上仙 6年前 (2019-09-03) 1317浏览 330个赞
实现示例: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) 2877浏览 0评论2806个赞
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) 3020浏览 0评论2958个赞
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) 1937浏览 0评论693个赞
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) 1801浏览 0评论166个赞
python计算数组、元祖等列表元素的和print( sum([1,2,3])) 返回值:6……继续阅读 » 水墨上仙 6年前 (2019-08-08) 2000浏览 2333个赞
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) 1686浏览 2923个赞
def isAString(anobj):return isinstance(anobj, basestring)def isAString(anobj): return isinstance(anobj, basestring)……继续阅读 » 水墨上仙 6年前 (2019-08-08) 3079浏览 678个赞
multipart/form-data类型的POST实体结构相对来说(常规的POST正文采用application/x-www-form-urlencoded格式)比较复杂,它常用于文件上传。下面是一个multipart/form-data格式的POST实体示例-----------------------------114782935826962 ……继续阅读 » 水墨上仙 6年前 (2019-08-08) 2502浏览 1256个赞
python写日志的封装类# encoding:utf-8import sysimport loggingimport time def writeLog(message): logger=logging.getLogger() filename = time.strftime('%Y-%m-%d'……继续阅读 » 水墨上仙 6年前 (2019-08-08) 3023浏览 2285个赞
python链接Oracle数据库的代码,需要引用cx_Oracle库#coding=UTF-8 import cx_Oracle def hello(): '''Hello cx_Oracle示例: 1)打印数据库版本信息. 2)查询表数据.'……继续阅读 » 水墨上仙 6年前 (2019-08-08) 2094浏览 1969个赞
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) 2132浏览 1172个赞
python正则查找所有匹配的字符串import re p = re.compile(r'\d+')print p.findall('one1two2three3four4') ### output #### ['1', '2', '3……继续阅读 » 水墨上仙 6年前 (2019-08-08) 2023浏览 1268个赞
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) 2042浏览 2772个赞
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) 2016浏览 665个赞
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) 2889浏览 2201个赞
由于Python设计的限制(我说的是咱们常用的CPython)。最多只能用满1个CPU核心。Python提供了非常好用的多进程包multiprocessing,你只需要定义一个函数,Python会替你完成其他所有事情。借助这个包,可以轻松完成从单进程到并发执行的转换。1、新建单一进程如果我们新建少量进程,可以如下:import multiproces……继续阅读 » 水墨上仙 6年前 (2019-08-08) 2617浏览 563个赞
在2.6才开始使用multiprocessing 是一个使用方法类似threading模块的进程模块。允许程序员做并行开发。并且可以在UNIX和Windows下运行。通过创建一个Process 类型并且通过调用call()方法spawn一个进程。下面是该模块的一个测试程序。效果非常好#!/usr/bin/env python#coding=utf-……继续阅读 » 水墨上仙 6年前 (2019-08-08) 2686浏览 2773个赞
python subprocess模块 监控子进程的2种方式 忙等待和立即返回同时设置子进程超时时间一:循环 忙等 子进程结束import subprocess import os import time tt = '555' cmd = "python /home/1……继续阅读 » 水墨上仙 6年前 (2019-08-08) 1542浏览 488个赞
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) 1458浏览 1632个赞
Advanced Python Scheduler是一个python的定时执行任务的框架,调用无比简单,不用自己写定时器了 演示代码from apscheduler.scheduler import Schedulersched = Scheduler()@sched.i……继续阅读 » 水墨上仙 6年前 (2019-08-08) 1452浏览 150个赞
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) 1635浏览 2279个赞
python通过xmlrpc进行远程调用的范例演示服务器端代码# -*- coding: utf-8 -*-import SimpleXMLRPCServer#server 上面的程式碼 def Show_me_some_message(sMsg):#從遠端呼叫並且帶入參數 print "I see your call……继续阅读 » 水墨上仙 6年前 (2019-08-08) 1810浏览 2962个赞
Go语言的string模块包含了ToLower和ToUpper函数,用于将字符串转换成小写和大写package mainimport ( "fmt" "strings")func main() { fmt.Println(strings.ToUpper("hello wo……继续阅读 » 水墨上仙 6年前 (2019-08-08) 1641浏览 1433个赞
select 语句使得一个 goroutine 在多个通讯操作上等待。select 会阻塞,直到条件分支中的某个可以继续执行,这时就会执行那个条件分支。当多个都准备好的时候,会随机选择一个。package mainimport "fmt"func fibonacci(c, quit chan int) { ……继续阅读 » 水墨上仙 6年前 (2019-08-08) 2914浏览 2067个赞
通过两种方式提供基于HTML模板的多变量值替换。另外附加一个数组迭代的示例。 传入map实现多值替换package mainimport ( "html/template" "os")func main() { t,……继续阅读 » 水墨上仙 6年前 (2019-08-08) 2932浏览 1355个赞
JavaScript转向跳转(redirect)<script type="text/javascript"><!-- window.location = "http://www.google.com/" //--></script> ……继续阅读 » 水墨上仙 6年前 (2019-08-08) 3008浏览 1000个赞
一个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) 3125浏览 2397个赞
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) 1508浏览 195个赞
python rpc twisted 服务端和客户端代码演示#服务器端代码如下from twisted.web import xmlrpc, serverclass Example(xmlrpc.XMLRPC): """ An example object to be published. ……继续阅读 » 水墨上仙 6年前 (2019-08-03) 1910浏览 910个赞
wxpython自定义语法高亮控件,支持python语法高亮,只需要稍加修改就可以支持其它语言的语法高亮import keywordimport wximport wx.stc as stcimport images#--------------------------------------------------------……继续阅读 » 水墨上仙 6年前 (2019-08-03) 2777浏览 1329个赞
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) 2981浏览 485个赞
Go语言计算指定年月的天数package mainimport ( "fmt" "bufio" "os" "regexp" "strconv")func main() { year := input("year&……继续阅读 » 水墨上仙 6年前 (2019-08-03) 3118浏览 138个赞
在JavaScript里乘法比除法的性能要好得多,所以同样的程序如果能用乘法就不用除法//除法,慢var my_variable = 5 / 2;//乘法,快var my_variable = 5 * 0.5; ……继续阅读 » 水墨上仙 6年前 (2019-08-03) 2148浏览 385个赞
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) 1998浏览 1142个赞
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) 2246浏览 1702个赞