JavaScript定义变量也和性能有关,看看下面的代码你就明白了,只是把变量声明换了个地方就可以让代码变快//未优化的代码,很慢for(var i = 0; i < 1000; i++){var my_variable = 'This is my variable';// Do something with my_va……继续阅读 » 6年前 (2021-01-15) 1911浏览 2138个赞
下面的代码通过Tkinter制作windows窗口界面,然后时间了一个简单的倒计时功能,代码可以直接运行# Countdown using Tkinter from Tkinter import *import timeimport tkMessageBoxclass App: def __init__(self,master……继续阅读 » 6年前 (2021-01-13) 2341浏览 1008个赞
python获得文件扩展名import os.path def file_extension(path): return os.path.splitext(path)[1] ……继续阅读 » 6年前 (2021-01-13) 3505浏览 2327个赞
python通过win32com库播放mp3文件# Python supports COM, if you have the Win32 extensions# check your Python folder eg. D:\Python23\Lib\site-packages\win32com# also http://starship.pyt……继续阅读 » 6年前 (2021-01-13) 1813浏览 1825个赞
python删除整个目录(目录非空),os.rmdir()只能删除空目录,下面的函数可以删除整个非空目录import osimport shutildef CleanDir( Dir ): if os.path.isdir( Dir ): paths = os.listdir( Dir ) for pa……继续阅读 » 6年前 (2021-01-13) 3394浏览 1483个赞
python 通关sleep函数等待到明天再执行def waitToTomorrow(): """Wait to tommorow 00:00 am""" tomorrow = datetime.datetime.replace(datetime.datetime.now……继续阅读 » 6年前 (2020-11-25) 2225浏览 1155个赞
有些JS是可以后加载的,如果一直等待JS加载完成可能非常影响网页上的其它功能实现,比如计数器一类的,jQuery可以对JS进行动态加载。方法1:$.getscript("test.js");方法2:function loadjs(file){ var head = $('head').remo……继续阅读 » 6年前 (2020-11-25) 2989浏览 364个赞
JavaScript随机打乱数组function Shuffle(o) { for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x); return o;};使用方法var testArray = ……继续阅读 » 6年前 (2020-11-18) 2554浏览 1825个赞
Python遍历字符串中的每一个字符直接用for 语句#遍历字符串a = 'asd'for q in a: print(q)# 输出结果为asd ……继续阅读 » 6年前 (2020-11-16) 2321浏览 874个赞
python旋转图片的代码# rotate an image counter-clockwise using the PIL image library# free from: http://www.pythonware.com/products/pil/index.htm# make sure to install PIL after your……继续阅读 » 6年前 (2020-11-16) 3184浏览 437个赞
python 计算字符串长度,一个中文算两个字符,先转换成utf8,然后通过计算utf8的长度和len函数取得的长度,进行对比即可知道字符串内中文字符的数量,自然就可以计算出字符串的长度了。来源:http://www.75271.comvalue=u'脚本12'length = len(value)utf8_length = ……继续阅读 » 6年前 (2020-11-16) 3376浏览 801个赞
python从网络端口读取文本数据# To test it with netcat, start the script and execute:# # echo "Hello, cat." | ncat.exe 127.0.0.1 12345#import socketHOST = 'localhos……继续阅读 » 6年前 (2020-11-16) 2698浏览 2694个赞
windows下通过批处理获得本机mac地址@ECHO OFF:: Check OS versionIF NOT "%OS%"=="Windows_NT" GOTO SyntaxSETLOCAL:: Check command line argumentsIF NOT "%~2"……继续阅读 » 6年前 (2020-11-16) 3257浏览 934个赞
转自:http://blog.csdn.net/marising/article/details/6551692在很久以前,我写了一个系列,Python和C和C++的交互,如下http://blog.csdn.net/marising/archive/2008/08/28/2845339.aspx目的是解决Python和C/C++的互操作性的问题,假如……继续阅读 » 6年前 (2020-11-16) 2636浏览 1794个赞
回文,亦称回环,是正读反读都能读通的句子,亦有将文字排列成圆圈者,是一种修辞方式和文字游戏。下面的代码用于检测一个字符串是否是回文/**检测回文串: * 先判断该字符的第一个和最后一个字符是否相等。如果相等,检查第二个字符和倒数第二个字符 * 是否相等。这个过程继续进行,直到出现不配陪的情况或者字符串的所有字符都检验完了。当字 ……继续阅读 » 6年前 (2020-11-16) 3438浏览 2866个赞
python显示生日是星期几# find the day of the week of a given date# Python will trap impossible dates like (1900, 2, 29)# tested with Python24 vegaseat 01aug2005from datetime i……继续阅读 » 6年前 (2020-11-16) 1941浏览 545个赞
python比较两段文本的不同之处# find the difference between two texts# tested with Python24 vegaseat 6/2/2005import difflibtext1 = """The World's Shortest Books:……继续阅读 » 6年前 (2020-11-16) 3416浏览 2885个赞
C++通过递归进行回文判断#include using namespace std; //将一整数逆序后放入一数组中(要求递归实现) int IsRound(char *str,int len) { if(*str==*(str+len-1)) return IsRound(str+1,len-2); if(le……继续阅读 » 6年前 (2020-11-16) 2285浏览 564个赞
python获取一组汉字拼音的首字母来源:http://wangwei007.blog.51cto.com/68019/983289作者:lover007#!/usr/bin/env python # -*- coding: utf-8 -*- def multi_get_letter(str_input): if ……继续阅读 » 6年前 (2020-11-13) 1669浏览 2138个赞
python监控本机cpu的利用百分比情况import wmiimport timec = wmi.WMI()while True: for cpu in c.Win32_Processor(): timestamp = time.strftime('%a, %d %b %Y %H:%M:%S',……继续阅读 » 6年前 (2020-11-13) 2349浏览 2149个赞
python自动连接ssh的代码#!/usr/bin/python#-*- coding:utf-8 -*-import sys, time, ostry: import pexpectexcept ImportError: print """ You must insta……继续阅读 » 6年前 (2020-11-13) 1666浏览 1515个赞
下面这段代码意思是,如果b为None则c等于a,否则c=b,用python写起来就容易多了a=100b=50c=a if b is None else bprint(c)#输出结果为50,这段代码相当于if b is None: c = aelse: c = b ……继续阅读 » 6年前 (2020-11-13) 2576浏览 2294个赞
想sqlite插入一条记录后,马上获得自动生成的id编号的方法connection=sqlite3.connect(':memory:')cursor=connection.cursor()cursor.execute('''CREATE TABLE foo (id integer primary ……继续阅读 » 6年前 (2020-11-13) 3847浏览 1273个赞
JavaScript判断浏览器是否是IEvar isMSIE = /*@cc_on!@*/0;if (isMSIE) { // do IE-specific things} else { // do non IE-specific things} ……继续阅读 » 6年前 (2020-11-06) 4436浏览 2081个赞
JavaScript不要在for循环语句里使用计算表达式和函数//慢for(var i = 0; i < my_array.length; i++)//也很慢for(var i = 0; i < myMethod(); i++)//快var length = my_array.length;for(var i = 0; ……继续阅读 » 6年前 (2020-11-06) 2582浏览 1156个赞
一段简单的js代码,让浏览器自动点击按钮<script type="text/javascript"> function init(){ document.getElementById('button1').click(); } onl……继续阅读 » 6年前 (2020-11-06) 3164浏览 809个赞
此代码主要是为了演示如何通过按钮来更新grid的数据import wx, wx.gridclass GridData(wx.grid.PyGridTableBase): _cols = "a b c".split() _data = [ "1 2 3".split(), ……继续阅读 » 6年前 (2020-04-13) 1812浏览 1225个赞
在python脚本内运行linux命令#/usr/bin/env pythonimport subprocessclass RunCmd(object): def cmd_run(self, cmd): self.cmd = cmd subprocess.call(self.cmd, shell=Tru……继续阅读 » 7年前 (2019-09-03) 2800浏览 408个赞
Python输出两个字符串中相同的字符,计算两个字符串的交集import setsmagic_chars = sets.Set('abracadabra')poppins_chars = sets.Set('supercalifragilisticexpialidocious')print '&……继续阅读 » 7年前 (2019-09-03) 2617浏览 1627个赞
python提供了非常方便的日志模块#-*- coding:utf-8 -*-import logging# 配置日志信息logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(name)-12s %(levelname)-……继续阅读 » 7年前 (2019-09-03) 2402浏览 2436个赞
split(string[, maxsplit]) | re.split(pattern, string[, maxsplit]):按照能够匹配的子串将string分割后返回列表。maxsplit用于指定最大分割次数,不指定将全部分割。import re p = re.compile(r'\d+')print p.spli……继续阅读 » 7年前 (2019-09-03) 2979浏览 776个赞
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)……继续阅读 » 7年前 (2019-09-03) 2266浏览 2894个赞
python统计文本文件内单词数量# count lines, sentences, and words of a text file# set all the counters to zerolines, blanklines, sentences, words = 0, 0, 0, 0print '-' * 50tr……继续阅读 » 7年前 (2019-09-03) 2889浏览 1569个赞
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……继续阅读 » 7年前 (2019-09-03) 3202浏览 1214个赞
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 { ……继续阅读 » 7年前 (2019-09-03) 1773浏览 2887个赞
Go语言写入字符串到文件代码package main import "fmt"import "os"func main() { fileName := "test.dat" dstFile,err := os.Create(fileName) if err!=nil……继续阅读 » 7年前 (2019-09-03) 2366浏览 1129个赞
go语言里使用scp的范例// https://blogs.oracle.com/janp/entry/how_the_scp_protocol_workspackage mainimport ( "code.google.com/p/go.crypto/ssh" "crypto" &q……继续阅读 » 7年前 (2019-09-03) 2084浏览 461个赞
本范例演示了JS中如何通过String.prototype自定义字符串操作协议,本代码定义了两个操作方法,一个用于清除html标签,一个用来转换html标签,都非常有用String.prototype.stripslashes = function(){ return this.replace(/<.*?>/g, '……继续阅读 » 7年前 (2019-09-03) 2941浏览 1480个赞
python计算数组、元祖等列表元素的和print( sum([1,2,3])) 返回值:6……继续阅读 » 7年前 (2019-08-08) 2652浏览 1739个赞
python遍历字符串中的字符word = raw_input("Enter a word: ")print "\nHere's each letter in your word:"for letter in word: print letter……继续阅读 » 7年前 (2019-08-08) 3133浏览 2592个赞
def isAString(anobj):return isinstance(anobj, basestring)def isAString(anobj): return isinstance(anobj, basestring)……继续阅读 » 7年前 (2019-08-08) 2639浏览 1063个赞
multipart/form-data类型的POST实体结构相对来说(常规的POST正文采用application/x-www-form-urlencoded格式)比较复杂,它常用于文件上传。下面是一个multipart/form-data格式的POST实体示例-----------------------------114782935826962 ……继续阅读 » 7年前 (2019-08-08) 2963浏览 596个赞
python写日志的封装类# encoding:utf-8import sysimport loggingimport time def writeLog(message): logger=logging.getLogger() filename = time.strftime('%Y-%m-%d'……继续阅读 » 7年前 (2019-08-08) 2743浏览 2757个赞
python链接Oracle数据库的代码,需要引用cx_Oracle库#coding=UTF-8 import cx_Oracle def hello(): '''Hello cx_Oracle示例: 1)打印数据库版本信息. 2)查询表数据.'……继续阅读 » 7年前 (2019-08-08) 3318浏览 606个赞
python 给目录下的图片批量加水印water.py 放到 图片文件夹里 然后cd 到当前文件夹 python water.py#coding=utf-8import Imageimport os#print list[0]#exit()def getlogo(x1,y1): im =Image.open("./&qu……继续阅读 » 7年前 (2019-08-08) 3456浏览 601个赞