最近在做SEO的时候,为了让发的外链能够快速的收录,想到了利用ping的功能,google和百度都有相关的ping介绍,有兴趣的朋友可以去看看相关的知识。实现ping功能除了可以用一些开源的博客程序,比如WP,它是可以在后台设置ping地址的,只要设置好以后,你发帖子,就会自动的通知搜索引擎,我的博客已经更新了,而今天我用的方法是不通过WP等带有ping功能……继续阅读 » 水墨上仙 6年前 (2019-08-02) 2089浏览 165个赞
python通过tarfile模块压缩文件夹import tarfileimport osimport sysuser = os.getenv('USERNAME')filename = '/home/%s/tmp.tgz' % userprint 'The tar file was ……继续阅读 » 水墨上仙 6年前 (2019-08-02) 2329浏览 1748个赞
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) 2411浏览 855个赞
如果用户访问http://地址,这段代码可以将用户自动转向https://地址window.location = "https://" + window.location.hostname + window.location.pathname + window.location.search; ……继续阅读 » 水墨上仙 6年前 (2019-08-02) 2005浏览 2337个赞
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) 1382浏览 2321个赞
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) 1623浏览 538个赞
django中是不能直接调用函数的,可以通过自定义filter来实现#template_filters.py@register.filterdef template_args(instance, arg): """ stores the arguments in a separate insta……继续阅读 » 水墨上仙 6年前 (2019-08-02) 2592浏览 384个赞
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) 1585浏览 847个赞
JavaScript一行代码清除html标签var StrippedString = OriginalString.replace(/(<([^>]+)>)/ig,""); ……继续阅读 » 水墨上仙 6年前 (2019-08-02) 2880浏览 2671个赞
// Define the XML DocumentNSXMLDocument* doc = [[NSXMLDocument alloc] initWithXMLString:[NSString stringWithContentsOfFile:@"/folder/with/sample.xml"]]; // C……继续阅读 » 水墨上仙 6年前 (2019-08-02) 2108浏览 775个赞
美联储历次降息/加息周期及时间一览表 美联储历次降息周期时间表:美联储历次加息一览表历次美联储加息加息时间基点美元指数利率市场观点美联储第一次加息2004年6月30日2588.80.0125美联储加息在意料之中美联储第二次加息2004年8月10日2588.790.015美联储加息表明经济……继续阅读 » 开心洋葱 6年前 (2019-08-01) 2361浏览 0评论1160个赞
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) 1790浏览 1784个赞
python计算代码执行时间import time start = time.time() '''code you want to time goes here''' end = time.time()elapsed = end - startprint "Time ……继续阅读 » 水墨上仙 6年前 (2019-07-11) 2134浏览 429个赞
我们知道python里没有switch语句,只能用多个if语句来实现,但python的字典却是万能的,下面的代码用字典实现了类似switch的功能try: sql_type = { 'STRING': 'TEXT', 'DOUBLE': 'NU……继续阅读 » 水墨上仙 6年前 (2019-07-11) 1377浏览 679个赞
有两个数组,它们长度相同,你希望把两个数组合并成一个字典,第一个数组的作为键,第二个数组作为值,python都可以很简单的帮你实现keys = [1, 2, 3, 4]values = [55, 56, 57, 58] new_dict = dict(zip(keys, values))……继续阅读 » 水墨上仙 6年前 (2019-07-11) 3032浏览 1754个赞
python在当前文件夹下设置一个简单的http服务器,执行后可以直接访问:http://127.0.0.1:8000就可以看到当前文件夹下的文件列表python -m SimpleHTTPServer……继续阅读 » 水墨上仙 6年前 (2019-07-11) 1818浏览 2613个赞
一段用来判断图片是否是色情图片的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) 1679浏览 1106个赞
当你在函数定义内声明变量的时候,它们与函数外具有相同名称的其他变量没有任何关系,即变量名称对于函数来说是 局部 的。这称为变量的 作用域 。所有变量的作用域是它们被定义的块,从它们的名称被定义的那点开始。#!/usr/bin/python# Filename: func_local.pydef func(x): print 'x ……继续阅读 » 水墨上仙 6年前 (2019-07-11) 1474浏览 2003个赞
python添加字符到文件代码with open("filename","a") as out: out.write("aString") ……继续阅读 » 水墨上仙 6年前 (2019-07-11) 1270浏览 2635个赞
python链接字符串的几种方法 方法1:直接通过加号操作符相加foobar = ‘foo’ + ‘bar’ 方法2:join方法list_of_strings = ['abc', &……继续阅读 » 水墨上仙 6年前 (2019-07-11) 1824浏览 1778个赞
子类化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) 2089浏览 770个赞
下面的代码可以从网络读取一张图片,不需要保存为本地文件,直接通过Image模块对图片进行处理,这里使用到了cStringIO库,主要是把从网络读取到的图片数据模拟成本地文件。import urllib2import Imageimport cStringIOdef ImageScale(url,size): file = cStringI……继续阅读 » 水墨上仙 6年前 (2019-07-11) 2710浏览 2534个赞
一个python高强度密码生成器,可以指定要生成的密码长度from os import urandomfrom random import choicechar_set = {'small': 'abcdefghijklmnopqrstuvwxyz', 'nums'……继续阅读 » 水墨上仙 6年前 (2019-07-11) 3084浏览 1925个赞
在编码,解码过程中,会出现某些字符始终无法处理,此时该字符出现在(‘[\\x00-\\x08\\x0b-\\x0c\\x0e-\\x1f]’)范围值呢,去掉这些字符即可顺利编码,import re s = re.compile('[\\x00-\\x08\\x0b-\\x0c\\x0e-\\x1f]').s……继续阅读 » 水墨上仙 6年前 (2019-07-11) 2164浏览 2897个赞
python中id()函数的实用研究实例>>> a = 2.5 >>> b = 2.5 >>> c = b >>> a is c 输出:False >>> a ……继续阅读 » 水墨上仙 6年前 (2019-07-11) 2832浏览 1892个赞
python判断当前用户是否是root,这段代码只能在unix核心的系统运行(unix,linux,mac等),不能在windows下运行import osif os.geteuid() != 0: print "This program must be run as root. Aborting." sys.ex……继续阅读 » 水墨上仙 6年前 (2019-07-11) 1489浏览 1608个赞
python获取当前运行程序所在的路径import os.pathprint os.path.realpath(__file__)……继续阅读 » 水墨上仙 6年前 (2019-07-11) 3015浏览 301个赞
范例:[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) 1389浏览 978个赞
用python来清除字符串里的html标签>>> print stripTags(‘Hello, world !‘)Hello, world !def stripTags(s): ''' Strips HTML tags. Taken from http://aspn……继续阅读 » 水墨上仙 6年前 (2019-07-11) 2363浏览 764个赞
这段代码不用google api,而是直接抓取Google的搜索结果页,找到需要的链接后存储在links.txt, Google的搜索页面可能会变化,这段代码也需要修改import re,urllib,urllib2class GoogleHarvester: re_links = re.compile(r'<a class……继续阅读 » 水墨上仙 6年前 (2019-07-11) 2204浏览 1071个赞
这是一个python通过urllib直接登陆网站,并处理网站的session和cookieimport cookielib, urllib, urllib2login = 'ismellbacon123@yahoo.com'password = 'login'# Enable cookie support ……继续阅读 » 水墨上仙 6年前 (2019-07-11) 1735浏览 2617个赞
wxpython用来创建窗口应用程序,但有时候我们希望能在控制台输出一些异常或者错误提示,这段代码能够帮助你实现import sysSTDERR = sys.stderr # Keep stderr because wxPyhon will redirect it.import wx[...your wxPython program goes ……继续阅读 » 水墨上仙 6年前 (2019-07-11) 2232浏览 2189个赞
python并不提供抽象类的写法,但是如果你非要严格实现抽象类,可以使用下面的代码,实际上就是不允许用户直接调用父类的方法,如果用户调用了,则给出错误提示。class myAbstractClass: def __init__(self): if self.__class__ is myAbstractClass: ……继续阅读 » 水墨上仙 6年前 (2019-07-11) 2234浏览 1902个赞
python可以非常容易的捕获程序的输出信息,同时也可以传递给命令行程序信息#捕获程序输出信息#!/usr/bin/pythonimport subprocessmyprocess = subprocess.Popen(['net','statistics','workstation']……继续阅读 » 水墨上仙 6年前 (2019-07-11) 1423浏览 290个赞
用Python实现一个简单的算术游戏来源:http://blog.csdn.net/buaa_shang/article/details/8315829#!/usr/bin/env pythonfrom operator import add, sub from random import randint, choiceops = {'……继续阅读 » 水墨上仙 6年前 (2019-07-11) 2762浏览 291个赞
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>……继续阅读 » 水墨上仙 6年前 (2019-07-11) 2241浏览 2018个赞
python编写简单抽奖系统#!/usr/bin/env python#coding=utf-8from Tkinter import *import timeimport randomclass App: def __init__(self,master): frame = Frame(master) frame.pack() ……继续阅读 » 水墨上仙 6年前 (2019-07-11) 1584浏览 1985个赞
我们知道python中有个range函数用来产生一个范围内的数字数组,但是浮点数没有,我们来定义一个#python中的range函数支持步进,如下:>>> print range(2,15,3)[2, 5, 8, 11, 14]#但是浮点数不支持range函数,自己定义一个类似的def floatrange(start,sto……继续阅读 » 水墨上仙 6年前 (2019-07-11) 1960浏览 2425个赞
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……继续阅读 » 水墨上仙 6年前 (2019-07-11) 2693浏览 592个赞
通过python的feedparse模块可以很容易的分析出rss的内容#!/usr/bin/env python# [代码名字: Parse an RSS feed]# [代码分类: feedparser] # [代码描述: Parse and iterate over the items in an RSS feed]# [代码作者: Ti……继续阅读 » 水墨上仙 6年前 (2019-07-11) 2968浏览 2979个赞
python判断字符串包含的方法,所有语言中,python的这种判断方法可以说是最直观简单的。#!/usr/bin/env python## [代码名字: String contains string test]# [代码分类: Python Core]# [代码描述: Test if a string contains another str……继续阅读 » 水墨上仙 6年前 (2019-07-11) 2649浏览 1110个赞
C语言多种方法求解字符串编辑距离问题编辑距离:通过插入、删除、替换一个字符(和交换相邻字符)的操作,使得字符串A和字符串B相同,而最少的操作次数就是编辑距离。如字符串abcd和aca的距离是2/* 递归搜索 */int calDistance1(char *ptrX, int xbeg, int xend, char *ptrY, int ybeg, i……继续阅读 » 水墨上仙 6年前 (2019-07-11) 2903浏览 1814个赞
javascript为数字添加逗号千分符function CommaFormatted(amount) { var delimiter = ","; // replace comma if desired var a = amount.split('.',2) var d = a[1]; var i = pa……继续阅读 » 水墨上仙 6年前 (2019-07-11) 2230浏览 1057个赞
php查询mysql数据库prepare语句用法,使用prepare可以优化数据库查询$mysql = new mysqli('localhost', 'root', 'root', 'databaseName') or die('There was a proble……继续阅读 » 水墨上仙 6年前 (2019-07-11) 3164浏览 1271个赞
调用JavaScript数组元素的多个属性或者方法,应该先把数组元素放到变量里,然后依靠变量调用,不要每次都直接使用数组元素调用//直接使用数组元素调用,慢myArray[myIndex].myMethod1();myArray[myIndex].myMethod2();myArray[myIndex].my_variable;//放到变量里再通过……继续阅读 » 水墨上仙 6年前 (2019-07-11) 1796浏览 2909个赞