Go语言计算指定年月的天数package mainimport ( "fmt" "bufio" "os" "regexp" "strconv")func main() { year := input("year&……继续阅读 » 水墨上仙 7年前 (2019-08-03) 3165浏览 1132个赞
在JavaScript里乘法比除法的性能要好得多,所以同样的程序如果能用乘法就不用除法//除法,慢var my_variable = 5 / 2;//乘法,快var my_variable = 5 * 0.5; ……继续阅读 » 水墨上仙 7年前 (2019-08-03) 2460浏览 971个赞
Pascal求N以内的完美数完全数(Perfect number),又称完美数或完备数,是一些特殊的自然数。它所有的真因子(即除了自身以外的约数)的和(即因子函数),恰好等于它本身。program bill02;var m,n,y,i,j,s,ss,z:longint;a:array[1..10000] of integer;beginre……继续阅读 » 水墨上仙 7年前 (2019-08-02) 1359浏览 2619个赞
python集合使用范例# sets are unordered collections of unique hashable elements# Python23 tested vegaseat 09mar2005# Python v2.4 has sets built inimport setsprint "……继续阅读 » 水墨上仙 7年前 (2019-08-02) 1787浏览 1768个赞
python读写ini配置文件import ConfigParserimport osclass ReadWriteConfFile: currentDir=os.path.dirname(__file__) filepath=currentDir+os.path.sep+"inetMsgConfigure.ini&……继续阅读 » 水墨上仙 7年前 (2019-08-02) 1857浏览 816个赞
设有一个m×n的棋盘(2≤m≤50,2≤n≤50),在棋盘上任一点有一个中国象棋“马”,马走的规则为:马走日字;马只能向右走。当m,n给出后,同时给出马起始的位置和终点的位置,试找出从起点到终点所有路径的数目。输入:    m,n,x1,y1,x2,y2 (分别表示m,n、起点……继续阅读 » 水墨上仙 7年前 (2019-08-02) 2159浏览 2228个赞
最近在做SEO的时候,为了让发的外链能够快速的收录,想到了利用ping的功能,google和百度都有相关的ping介绍,有兴趣的朋友可以去看看相关的知识。实现ping功能除了可以用一些开源的博客程序,比如WP,它是可以在后台设置ping地址的,只要设置好以后,你发帖子,就会自动的通知搜索引擎,我的博客已经更新了,而今天我用的方法是不通过WP等带有ping功能……继续阅读 » 水墨上仙 7年前 (2019-08-02) 1446浏览 857个赞
python通过tarfile模块压缩文件夹import tarfileimport osimport sysuser = os.getenv('USERNAME')filename = '/home/%s/tmp.tgz' % userprint 'The tar file was ……继续阅读 » 水墨上仙 7年前 (2019-08-02) 3153浏览 2536个赞
Windows下批处理返回今天是星期几保存下面的代码为:test.bat,执行后返回:It’s 周六 today@ECHO OFFFOR /F "tokens=*" %%A IN ('DATE/T') DO FOR %%B IN (%%A) DO SET Today=%%BECHO It'……继续阅读 » 水墨上仙 7年前 (2019-08-02) 3709浏览 2717个赞
如果用户访问http://地址,这段代码可以将用户自动转向https://地址window.location = "https://" + window.location.hostname + window.location.pathname + window.location.search; ……继续阅读 » 水墨上仙 7年前 (2019-08-02) 2375浏览 789个赞
java实现逆波兰表达式算法import java.util.ArrayList;import java.util.List;public class MyStack { private List l; private int size; public String top; public MyStack() { l ……继续阅读 » 水墨上仙 7年前 (2019-08-02) 2071浏览 2923个赞
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……继续阅读 » 水墨上仙 7年前 (2019-08-02) 3458浏览 151个赞
django中是不能直接调用函数的,可以通过自定义filter来实现#template_filters.py@register.filterdef template_args(instance, arg): """ stores the arguments in a separate insta……继续阅读 » 水墨上仙 7年前 (2019-08-02) 2287浏览 102个赞
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……继续阅读 » 水墨上仙 7年前 (2019-08-02) 2683浏览 123个赞
JavaScript一行代码清除html标签var StrippedString = OriginalString.replace(/(<([^>]+)>)/ig,""); ……继续阅读 » 水墨上仙 7年前 (2019-08-02) 4138浏览 471个赞
// Define the XML DocumentNSXMLDocument* doc = [[NSXMLDocument alloc] initWithXMLString:[NSString stringWithContentsOfFile:@"/folder/with/sample.xml"]]; // C……继续阅读 » 水墨上仙 7年前 (2019-08-02) 2238浏览 1972个赞
美联储历次降息/加息周期及时间一览表 美联储历次降息周期时间表:美联储历次加息一览表历次美联储加息加息时间基点美元指数利率市场观点美联储第一次加息2004年6月30日2588.80.0125美联储加息在意料之中美联储第二次加息2004年8月10日2588.790.015美联储加息表明经济……继续阅读 » 开心洋葱 7年前 (2019-08-01) 2206浏览 0评论624个赞
python 创建gtk应用程序,需要安装gtk包#!/usr/bin/env python## [代码名字: Create an Application Indicator]# [代码分类: Application Indicator]# [代码描述: How to create an application indicator and ad……继续阅读 » 水墨上仙 7年前 (2019-07-11) 1434浏览 1099个赞
python计算代码执行时间import time start = time.time() '''code you want to time goes here''' end = time.time()elapsed = end - startprint "Time ……继续阅读 » 水墨上仙 7年前 (2019-07-11) 3236浏览 1689个赞
我们知道python里没有switch语句,只能用多个if语句来实现,但python的字典却是万能的,下面的代码用字典实现了类似switch的功能try: sql_type = { 'STRING': 'TEXT', 'DOUBLE': 'NU……继续阅读 » 水墨上仙 7年前 (2019-07-11) 2236浏览 1531个赞
有两个数组,它们长度相同,你希望把两个数组合并成一个字典,第一个数组的作为键,第二个数组作为值,python都可以很简单的帮你实现keys = [1, 2, 3, 4]values = [55, 56, 57, 58] new_dict = dict(zip(keys, values))……继续阅读 » 水墨上仙 7年前 (2019-07-11) 4290浏览 2938个赞
python在当前文件夹下设置一个简单的http服务器,执行后可以直接访问:http://127.0.0.1:8000就可以看到当前文件夹下的文件列表python -m SimpleHTTPServer……继续阅读 » 水墨上仙 7年前 (2019-07-11) 2617浏览 1283个赞
一段用来判断图片是否是色情图片的python代码,安装了pil包既可以使用转自:http://blog.csdn.net/lanphadayimport sys, Image pic = '2.jpg'img = Image.open(pic).convert('YCbCr') w, h = img.……继续阅读 » 水墨上仙 7年前 (2019-07-11) 1613浏览 182个赞
当你在函数定义内声明变量的时候,它们与函数外具有相同名称的其他变量没有任何关系,即变量名称对于函数来说是 局部 的。这称为变量的 作用域 。所有变量的作用域是它们被定义的块,从它们的名称被定义的那点开始。#!/usr/bin/python# Filename: func_local.pydef func(x): print 'x ……继续阅读 » 水墨上仙 7年前 (2019-07-11) 1883浏览 537个赞
python添加字符到文件代码with open("filename","a") as out: out.write("aString") ……继续阅读 » 水墨上仙 7年前 (2019-07-11) 2970浏览 2188个赞
python链接字符串的几种方法 方法1:直接通过加号操作符相加foobar = ‘foo’ + ‘bar’ 方法2:join方法list_of_strings = ['abc', &……继续阅读 » 水墨上仙 7年前 (2019-07-11) 3224浏览 2528个赞
子类化wxPython application类class MyApp(wx.App): def OnInit(self): frame = wx.Frame(parent=None, id=-1, title=”Bare”) frame.Show() return True……继续阅读 » 水墨上仙 7年前 (2019-07-11) 2285浏览 2843个赞
下面的代码可以从网络读取一张图片,不需要保存为本地文件,直接通过Image模块对图片进行处理,这里使用到了cStringIO库,主要是把从网络读取到的图片数据模拟成本地文件。import urllib2import Imageimport cStringIOdef ImageScale(url,size): file = cStringI……继续阅读 » 水墨上仙 7年前 (2019-07-11) 1337浏览 199个赞
一个python高强度密码生成器,可以指定要生成的密码长度from os import urandomfrom random import choicechar_set = {'small': 'abcdefghijklmnopqrstuvwxyz', 'nums'……继续阅读 » 水墨上仙 7年前 (2019-07-11) 1717浏览 2793个赞
在编码,解码过程中,会出现某些字符始终无法处理,此时该字符出现在(‘[\\x00-\\x08\\x0b-\\x0c\\x0e-\\x1f]’)范围值呢,去掉这些字符即可顺利编码,import re s = re.compile('[\\x00-\\x08\\x0b-\\x0c\\x0e-\\x1f]').s……继续阅读 » 水墨上仙 7年前 (2019-07-11) 3268浏览 649个赞
python中id()函数的实用研究实例>>> a = 2.5 >>> b = 2.5 >>> c = b >>> a is c 输出:False >>> a ……继续阅读 » 水墨上仙 7年前 (2019-07-11) 1594浏览 981个赞
python判断当前用户是否是root,这段代码只能在unix核心的系统运行(unix,linux,mac等),不能在windows下运行import osif os.geteuid() != 0: print "This program must be run as root. Aborting." sys.ex……继续阅读 » 水墨上仙 7年前 (2019-07-11) 2095浏览 2107个赞
python获取当前运行程序所在的路径import os.pathprint os.path.realpath(__file__)……继续阅读 » 水墨上仙 7年前 (2019-07-11) 3297浏览 860个赞
范例:[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……继续阅读 » 水墨上仙 7年前 (2019-07-11) 1866浏览 2663个赞
用python来清除字符串里的html标签>>> print stripTags(‘Hello, world !‘)Hello, world !def stripTags(s): ''' Strips HTML tags. Taken from http://aspn……继续阅读 » 水墨上仙 7年前 (2019-07-11) 2930浏览 1760个赞
这段代码不用google api,而是直接抓取Google的搜索结果页,找到需要的链接后存储在links.txt, Google的搜索页面可能会变化,这段代码也需要修改import re,urllib,urllib2class GoogleHarvester: re_links = re.compile(r'<a class……继续阅读 » 水墨上仙 7年前 (2019-07-11) 3168浏览 1287个赞
这是一个python通过urllib直接登陆网站,并处理网站的session和cookieimport cookielib, urllib, urllib2login = 'ismellbacon123@yahoo.com'password = 'login'# Enable cookie support ……继续阅读 » 水墨上仙 7年前 (2019-07-11) 2836浏览 2227个赞
wxpython用来创建窗口应用程序,但有时候我们希望能在控制台输出一些异常或者错误提示,这段代码能够帮助你实现import sysSTDERR = sys.stderr # Keep stderr because wxPyhon will redirect it.import wx[...your wxPython program goes ……继续阅读 » 水墨上仙 7年前 (2019-07-11) 2404浏览 2882个赞
python并不提供抽象类的写法,但是如果你非要严格实现抽象类,可以使用下面的代码,实际上就是不允许用户直接调用父类的方法,如果用户调用了,则给出错误提示。class myAbstractClass: def __init__(self): if self.__class__ is myAbstractClass: ……继续阅读 » 水墨上仙 7年前 (2019-07-11) 2078浏览 360个赞
python可以非常容易的捕获程序的输出信息,同时也可以传递给命令行程序信息#捕获程序输出信息#!/usr/bin/pythonimport subprocessmyprocess = subprocess.Popen(['net','statistics','workstation']……继续阅读 » 水墨上仙 7年前 (2019-07-11) 2030浏览 874个赞
用Python实现一个简单的算术游戏来源:http://blog.csdn.net/buaa_shang/article/details/8315829#!/usr/bin/env pythonfrom operator import add, sub from random import randint, choiceops = {'……继续阅读 » 水墨上仙 7年前 (2019-07-11) 1483浏览 388个赞
python 读取tar文件#!/usr/bin/env python# [代码名字: Open a tar file]# [代码分类: tarfile]# [代码描述: Open's a tar file and list the entries]# [代码作者: Tim Voet <tim.voet@gmail.com>……继续阅读 » 水墨上仙 7年前 (2019-07-11) 1479浏览 1023个赞
python编写简单抽奖系统#!/usr/bin/env python#coding=utf-8from Tkinter import *import timeimport randomclass App: def __init__(self,master): frame = Frame(master) frame.pack() ……继续阅读 » 水墨上仙 7年前 (2019-07-11) 3343浏览 2799个赞
我们知道python中有个range函数用来产生一个范围内的数字数组,但是浮点数没有,我们来定义一个#python中的range函数支持步进,如下:>>> print range(2,15,3)[2, 5, 8, 11, 14]#但是浮点数不支持range函数,自己定义一个类似的def floatrange(start,sto……继续阅读 » 水墨上仙 7年前 (2019-07-11) 2948浏览 2232个赞
python通过给定的url抓取远程xml文件def get_xml(self, remote_addr): remote_file = urllib.urlopen(remote_addr) remote_data = remote_file.read() remote_file.close() self.REQUEST.RESPON……继续阅读 » 水墨上仙 7年前 (2019-07-11) 2059浏览 753个赞