Time of Update: 2016-06-06
1 將下面代碼拷貝到一個檔案,命名為asyncore.py 代碼如下:import socketimport selectimport sysdef ds_asyncore(addr,callback,timeout=5): s=socket.socket(socket.AF_INET,socket.SOCK_STREAM) s.connect(addr) r,w,e = select.select([s],[],[],timeout) if r:
Time of Update: 2016-06-06
代碼如下:# -*- coding: cp936 -*-from scapy.all import *from threading import Thread,Lock,activeCountBROADCASTMAC = getmacbyip('192.168.0.120')class Loop(Thread): def __init__(self,ip): Thread.__init__(self) self.ip = ip def run(self):
Time of Update: 2016-06-06
代碼如下:# -*- coding: cp936 -*-from scapy.all import *from threading import Thread,activeCountfrom random import randintclass Loop(Thread): def __init__(self,remoteAddr): Thread.__init__(self) self.remoteAddr = remoteAddr def
Time of Update: 2016-06-06
tcp.py 代碼如下:# -*- coding: cp936 -*-import socketfrom struct import *from time import ctime,sleepfrom os import systemsystem('title tcp sniffer')system('color 05')# the public network interfaceHOST = socket.gethostbyname(socket.gethostname())#
Time of Update: 2016-06-06
系統內容:VC6 +
Time of Update: 2016-06-06
昨天翻硬碟,找到一個好東西,可惜自己加了密碼自己不記得了。試了幾個常用的沒試出來,於是寫了這麼個小指令碼來替我嘗試。。呵呵,還真給解出來了。python指令碼內容如下,跑跑自己加密的壓縮包還不錯 代碼如下:# -*- coding: utf-8 -*-import sys,osdef IsElementUniq(list): """ 判斷list中的元素是否為唯一的 """ for word in list: if
Time of Update: 2016-06-06
代碼如下:#-*-coding:utf-8-*-'''Created on 2014年1月10日@author: hhdys'''import urllib.request,http.cookiejar,reclass Baidu: def login(self): cj = http.cookiejar.CookieJar() opener =
Time of Update: 2016-06-06
熟悉Java的jsoup包的話,對於Python的BeautifulSoup庫應該很容易上手。 代碼如下:#coding: utf-8import sysimport urllibimport urllib2from BeautifulSoup import BeautifulSoupquestion_word = "吃貨 程式員"url = "http://www.baidu.com/s?wd=" +
Time of Update: 2016-06-06
代碼如下:#! /usr/bin/python2.7# -- coding:utf-8 --import os, urllib,urllib2, thread,threadingimport re#匹配音樂urlreg=re.compile('{"name":"(.+?)".+?"rawUrl":"(.+?)",.+?}', re.I)class downloader(threading.Thread): def __init__(self, url, name):
Time of Update: 2016-06-06
代碼如下:# encoding:utf-8### 檔案名稱如:# 下吧.mp3##import os,refs=os.listdir('xb')for f in fs: ######方法一:partition擷取無用字元 #1.將檔案名稱以'['符分為3部分 #ls=f.partition('[') #2.ls[0]為需要檔案名稱,因此擷取ls[1:] #dirtystring = ''.join(ls[1:]) #3.開始替換 #newname=f.replace(dirtystring, '
Time of Update: 2016-06-06
前面已經介紹過幾種基本語句(print,import,指派陳述式),下面我們來介紹條件陳述式,迴圈語句。一. print和import的更多資訊1.1 使用逗號輸出A.列印多個運算式,用逗號隔開,會在每個參數之間插入一個空格符: 代碼如下:>>> print 'age:',42age: 42B.同時輸出文本和變數值,卻又不希望使用字串格式化: 代碼如下:>>> name = 'Peter'>>> greeting = 'Hello'>>> print
Time of Update: 2016-06-06
方法一: 代碼如下:f = open("foo.txt") # 返回一個檔案對象 line = f.readline() # 調用檔案的 readline()方法 while line: print line, # 後面跟 ',' 將忽略分行符號 # print(line, end = '') # 在 Python 3中使用 line = f.readline()
Time of Update: 2016-06-06
代碼如下:import pdbdef pdb_test(arg): for i in range(arg): print(i) return argpdb.run("pdb_test(3)") b 函數名、行號:打斷點,b可以查詢所有的斷點。 代碼如下:(Pdb) b pdb_testBreakpoint 1 at c:\users\plpcc\desktop\pdbtest.py:3(Pdb) bNum Type Disp Enb Where
Time of Update: 2016-06-06
內送郵件 代碼如下:import poplib,pdb,email,re,timefrom email import headerPOP_ADDR = r'pop.126.com'USER = ''PASS = ''CONFIG = ''def getYear(date): rslt = re.search(r'\b2\d{3}\b', date) return int(rslt.group())def getMonth(date): monthMap = {'Jan':1,'
Time of Update: 2016-06-06
模版基本介紹模板是一個文本,用於分離文檔的表現形式和內容。 模板定義了預留位置以及各種用於規範文檔該如何顯示的各部分基本邏輯(模板標籤)。 模板通常用於產生HTML,但是Django的模板也能產生任何基於文字格式設定的文檔。來一個項目說明1、建立MyDjangoSite項目具體不多說,參考前面。2、在MyDjangoSite(包含四個檔案的)檔案夾目錄下建立templates檔案夾存放模版。3、在剛建立的模版下建模版檔案user_info.html 代碼如下: 使用者資訊
Time of Update: 2016-06-06
關於string的split 和 join 方法對匯入os模組進行os.path.splie()/os.path.join() 貌似是處理機制不一樣,但是功能上一樣。1.string.split(str=' ',num=string.count(str)): 以str為分隔,符切片string,如果num有指定值,則僅分隔num個子字串。S.split([sep [,maxsplit]]) -> 由字串分割成的列表
Time of Update: 2016-06-06
代碼如下:# -*- coding: UTF-8 -*-import mysql.connector as dbimport client.tWeiboimport timeif __name__ == '__main__': connect = db.connect(user='root',db='collection',password='',host="127.0.0.1") cursor = connect.cursor() cursor.execute("SET SQL_MODE =
Time of Update: 2016-06-06
今天看到同事參與小米的搶購,幾經數個星期的嘗試,終於搶到了一台小米電視……看了一下小米的搶購流程,似乎可以用程式可破。於是想寫點東西玩玩(你懂的……),第一步肯定是先得類比登入小米帳號,當練手吧。用 Python 來實現吧,由於是寫一個Web應用,那麼架構就選 Tornado。首先是定義應用的 URL: 代碼如下:def main(): tornado.options.parse_command_line() application =
Time of Update: 2016-06-06
樹的定義樹是一種重要的非線性資料結構,直觀地看,它是資料元素(在樹中稱為結點)按分支關係組織起來的結構,很象自然界中的樹那樣。樹結構在客觀世界中廣泛存在,如人類社會的族譜和各種社會組織機構都可用樹形象表示。樹在電腦領域中也得到廣泛應用,如在編譯來源程式時,可用樹表示來源程式的文法結構。又如在資料庫系統中,樹型結構也是資訊的重要組織形式之一。一切具有層次關係的問題都可用樹來描述。樹結構的特點是:它的每一個結點都可以有不止一個直接後繼,除根結點外的所有結點都有且只有一個直接前驅。樹的遞迴定義如下:(
Time of Update: 2016-06-06
最近在搞基於python的webservice項目,今天為把環境給配好,折騰了不少時間,還是把配的過程記錄下來,以後備用:首先你系統上要有python,這個不必說啦,我系統上用的是2.7+其次,要用python進行webservice開發,還需要一些庫:lxml :命令列下 sudo easy_install lxml 就能安裝pytz : 命令列下 sudo easy_install pytz