用Python提取url链接中的域名与端口import urllib proto, rest = urllib.splittype("http://www.75271.com/11/12.htm") host, rest = urllib.splithost(rest) print host host, port……继续阅读 » 9年前 (2018-01-21) 3200浏览 1494个赞
冒泡法排序Go语言版func BubbleSort(nums []int) { unsorted := true for unsorted { unsorted = false for i := len(nums) - 1; i > 0; i-- { if nums[i……继续阅读 » 9年前 (2018-01-21) 2735浏览 2904个赞
go语言实现的简单http服务代码package mainimport ( "flag" "log" "net/http" "text/template")var addr = flag.String("addr&q……继续阅读 » 9年前 (2018-01-20) 2766浏览 1051个赞
go语言编写的猜数字的小游戏代码随机生成一个数字,输入一个数字看是否匹对,匹配则结速,反之提示是大了还是小了转自:http://www.waylau.compackage mainimport ( "bufio" "fmt" "math/rand" "os"……继续阅读 » 9年前 (2018-01-20) 2322浏览 635个赞
python自动修改本机网关的代码#!/usr/bin/python#auto change gateway Created By mickelfengimport osimport random,reg='gateway 192.168.1.'rand=random.randint(1,3)test='……继续阅读 » 9年前 (2018-01-20) 2454浏览 1055个赞
Go语言官方带了一个工具叫cgo,可以很方便的在Go语言代码中内嵌C代码或做C和Go代码的集成。下面是一段简单的在Go中内嵌C的实验代码:package main/*#include #include void say_hello() { printf("Hello World!\n");}*/……继续阅读 » 9年前 (2018-01-20) 1641浏览 573个赞
凡是线性回溯都可以归结为右递归的形式,也即是二叉树,因此对于只要求一个解的问题,采用右递归实现的程序要比回溯法要优美的多。def Test(queen,n): '''这个就不用说了吧,就是检验第n(下标,0-7)行皇后的位置是否合理''' q=queen[n] for i in xrange……继续阅读 » 9年前 (2018-01-20) 2973浏览 2832个赞
python检查序列seq 是否含有aset 中的项# -*- coding: utf-8 -*-def containsAny(seq, aset): """ 检查序列seq 是否含有aset 中的项 """ for c in seq: if c in ……继续阅读 » 9年前 (2018-01-20) 4658浏览 1132个赞
python十进制转二进制,可指定位数# convert a decimal (denary, base 10) integer to a binary string (base 2)# tested with Python24 vegaseat 6/1/2005def Denary2Binary(n): ''……继续阅读 » 9年前 (2018-01-20) 1976浏览 470个赞
在python里面excel的简单读写操作我这里推荐使用xlrd(特别是读操作)到http://pypi.python.org/pypi/xlrd 去下载 xlrd库;import xlrd def open_excel(fileName="simple.xls"): try: fileH……继续阅读 » 9年前 (2018-01-20) 1673浏览 1980个赞
用Python实现二分查找#!/usr/bin/env pythonimport sys def search2(a,m): low = 0 high = len(a) - 1 while(low <= high): mid = (low + high)/2 midval ……继续阅读 » 9年前 (2018-01-20) 2556浏览 2920个赞
一行代码实现python字符串反转输出import reastring = 'hello world'revchars = astring[::-1]print(revchars)输出结果dlrow olleh ……继续阅读 » 9年前 (2018-01-20) 3737浏览 2983个赞
你可能已经猜到 switch 可能的形式了。case 体会自动终止,除非用 fallthrough 语句作为结尾。package mainimport ( "fmt" "runtime")func main() { fmt.Print("Go runs on ") s……继续阅读 » 9年前 (2018-01-20) 3300浏览 1828个赞
在这个练习中,将会使用 Go 的并发特性来并行执行 web 爬虫。修改 Crawl 函数来并行的抓取 URLs,并且保证不重复。package mainimport ( "fmt")type Fetcher interface { // Fetch 返回 URL 的 body 内容,并且将在这个页面上……继续阅读 » 9年前 (2018-01-20) 2124浏览 1245个赞
channel 是有类型的管道,可以用 channel 操作符 <- 对其发送或者接收值。ch <- v // 将 v 送入 channel ch。v := <-ch // 从 ch 接收,并且赋值给 v。(“箭头”就是数据流的方向。)和 map 与 slice 一样,channel 使用前必须创建:ch := make(chan……继续阅读 » 9年前 (2018-01-20) 3426浏览 1443个赞
Go语言for当做while用法演示package mainimport "fmt"func main() { sum := 0 for { sum ++ if sum > 10{ break }else{ fmt.Println(sum) } }} ……继续阅读 » 9年前 (2018-01-20) 3787浏览 2787个赞
Go语言单个文件拷贝演示代码package mainimport "fmt"import "io"import "os"func main(){ w,err := CopyFile("filecopy.go","test.go") i……继续阅读 » 9年前 (2018-01-20) 2600浏览 1049个赞
读取源文件,去掉空行,并写到目标文件/** * Created with IntelliJ IDEA. * User: hyper-carrot * Date: 12-8-31 * Time: 下午4:04 * To change this template use File | Settings | File Templates.……继续阅读 » 9年前 (2018-01-20) 2561浏览 868个赞
websockets的bufferedAmount使用范例代码// 10k max buffer size.var THRESHOLD = 10240; // Create a New WebSocket connectionvar ws = new WebSocket("ws://w3mentor.com"); ……继续阅读 » 9年前 (2018-01-20) 1890浏览 1480个赞
Go语言模仿linux cat命令package mainimport ( "io" "os" "fmt" "bufio" "flag")var numberFlag = flag.Bool("n"……继续阅读 » 9年前 (2018-01-20) 3365浏览 1046个赞
python过滤字符串中不属于指定集合的字符的类# -*- coding: utf-8 -*-import setsclass Keeper(object): def __init__(self, keep): self.keep = sets.Set(map(ord, keep)) def __getitem……继续阅读 » 9年前 (2018-01-19) 2520浏览 558个赞
可以通过easy_install qrcode 安装,也可以到:https://github.com/lincolnloop/python-qrcode 下载简单用法import qrcodeimg = qrcode.make('Some data here')高级用法import qrcodeqr = qrcode.……继续阅读 » 9年前 (2018-01-10) 1853浏览 1797个赞
使用一个循环,不断的创建线程,直到出现异常,才通知它们。python真是个好东西。#!/usr/bin/env python #coding=gbk import threading import time, random, sys class Counter: def __init__(self):……继续阅读 » 9年前 (2018-01-09) 3479浏览 2309个赞
python实现的守护进程(Daemon)def createDaemon(): ”’Funzione che crea un demone per eseguire un determinato programma…”’ import os # create - fork 1 try: ……继续阅读 » 9年前 (2018-01-09) 2373浏览 2169个赞
Perl批量执行Linux安装程序和脚本#!/usr/bin/perl#use Cwd;sub ExecuteAll(){ local($dir) = @_; opendir(DIR,"$dir"|| die "can't open $dir"); local @files =rea……继续阅读 » 9年前 (2018-01-09) 3358浏览 2969个赞
python提取url中的域名和端口号import urllib proto, rest = urllib.splittype("http://www.75271.com/11/12.htm") host, rest = urllib.splithost(rest) print host host, port =……继续阅读 » 9年前 (2018-01-09) 1756浏览 1608个赞
来源:http://blog.csdn.net/sun7545526/article/details/8138603需求:设计一个”石头,剪子,布”游戏,有时又叫”Rochambeau”,你小时候可能玩过,下面是规则.你和你的对手,在同一时间做出特定的手势,必须是下面一种手势:石头,剪子,布.胜利者从下面的……继续阅读 » 9年前 (2018-01-09) 2225浏览 503个赞
python检查一个集合是否包含了另外一个集合的所有项>>> L1 = [1, 2, 3, 3]>>> L2 = [1, 2, 3, 4]>>> set(L1).difference(L2)set([ ])>>> set(L2).difference(L1)set(……继续阅读 » 9年前 (2018-01-09) 3784浏览 2449个赞
python字符串按单词反转输出方法1import reastring = 'hello world'revwords = ' '.join(reversed(astring.split()))print(revwords)方法2import reastring = 'hello ……继续阅读 » 9年前 (2018-01-09) 2357浏览 554个赞
python通过正则获取网页上的全部链接import re, urllibhtmlSource = urllib.urlopen("http://www.75271.com").read(200000)linksList = re.findall('<a href="(.*?)">.*?……继续阅读 » 9年前 (2018-01-09) 3012浏览 194个赞
程序会监听8080端口,然后简单的返回web/路径下的文件,假如只输入类似localhost:8080,会自动找到index.htmlpackage mainimport ( "net/http")func main() { http.Handle("/", http.FileServ……继续阅读 » 9年前 (2018-01-09) 2489浏览 2905个赞
Python获取CPU使用率、内存使用率、网络使用状态注:需要安装psutil库#!/usr/bin/env python## $Id: iotop.py 1160 2011-10-14 18:50:36Z g.rodola@gmail.com $## Copyright (c) 2009, Jay Loden, Giampaolo Ro……继续阅读 » 9年前 (2018-01-08) 1970浏览 1827个赞
python通过代理服务器访问ftp服务import urllib2# Install proxy support for urllib2proxy_info = { 'host' : 'proxy.myisp.com', 'port' : 3128, ……继续阅读 » 9年前 (2017-07-11) 3301浏览 846个赞
python3 压缩文件夹内的文件到zip'''Created on Dec 24, 2012将文件归档到zip文件,并从zip文件中读取数据@author: liury_lab'''# 压缩成zip文件from zipfile import * #@UnusedWil……继续阅读 » 9年前 (2017-07-11) 3236浏览 865个赞
/** 密码发生器 在对银行账户等重要权限设置密码的时候,我们常常遇到这样的烦恼:如果为了好记用生日吧,* 容易被破解,不安全;如果设置不好记的密码,又担心自己也会忘记;如果写在纸上,担心纸张被别人发现或弄丢了…* 这个程序的任务就是把一串拼音字母转换为6位数字(密码)。* 我们可以使用任何好记的拼音串(比如名字,王喜明,就写:wangx……继续阅读 » 9年前 (2017-07-11) 3098浏览 703个赞
python返回指定日期是一年中的第几周>>> import datetime>>> print datetime.datetime(2006,9,4).isocalendar()[1]36 ……继续阅读 » 9年前 (2017-07-11) 4096浏览 250个赞
golang日志记录库简单使用方法范例package mainimport ( "fmt" "log" "os")func main(){ logfile,err := os.OpenFile("/var/golang/75271.com.log",……继续阅读 » 9年前 (2017-07-04) 2244浏览 931个赞
asp.net将DataGrid控件中的数据导出Execl提供下载System.Web.UI.Control ctl=this.DataGrid1;//DataGrid1是你在窗体中拖放的控件HttpContext.Current.Response.AppendHeader("Content-Disposition","……继续阅读 » 9年前 (2017-07-04) 2341浏览 1434个赞
d157e0d7f137c9ffc8d65473e038ee86 是 “Hello world !” 使用 “mykey”作为key的签名结果>>> import hmac>>> print hmac.new("mykey","Hello ……继续阅读 » 9年前 (2017-07-04) 2263浏览 2482个赞
本代码运行后会减轻8088端口,用户访问:http://127.0.0.1:8088 或输出html代码:Hello World!#!/usr/bin/pythonimport BaseHTTPServerclass MyHandler(BaseHTTPServer.BaseHTTPRequestHandler): def do_GET(……继续阅读 » 9年前 (2017-07-04) 3035浏览 2361个赞
python读取文件同时输出行号和内容file = open('file.txt','r')for (num,value) in enumerate(file): print "line number",num,"is:",valuefile.close()……继续阅读 » 9年前 (2017-07-03) 3067浏览 1663个赞
python实现简单的soap客户端# $Id: testquote.py 2924 2006-11-19 22:24:22Z fredrik $# delayed stock quote demo (www.xmethods.com)from elementsoap.ElementSOAP import *class QuoteService……继续阅读 » 9年前 (2017-07-03) 2795浏览 1947个赞
python 递归搜索文件夹下的指定文件import osdef look_in_directory(directory): """Loop through the current directory for the file, if the current item is a directory……继续阅读 » 9年前 (2017-07-03) 2264浏览 1773个赞
python读取LDIF文件#!/usr/bin/python# -*- coding: iso-8859-1 -*-import ldif # ldif module from http://python-ldap.sourceforge.netclass testParser(ldif.LDIFParser): def __in……继续阅读 » 9年前 (2017-06-15) 2154浏览 1818个赞
python获取一组数据里的最大值max函数使用演示# 最简单的max(1, 2)max('a', 'b')# 也可以对列表和元组使用max([1,2])max((1,2))# 还可以指定comparator functionmax('ah', 'bf……继续阅读 » 9年前 (2017-06-15) 2968浏览 1208个赞