廢話少說,上幹活。for的基本操作for是用來迴圈的,是從某個對象那裡依次將元素讀取出來。看下面的例子,將已經學習過的資料對象用for迴圈一下,看看哪些能夠使用,哪些不能使用。同時也是複習一下過往的內容。複製代碼 代碼如下:>>> name_str = "qiwsir">>> for i in name_str: #可以對str使用for迴圈... print i,... q i w s i r>>> name_list = list(name_
本文執行個體講述了python解析網頁原始碼中的115網盤連結的方法。分享給大家供大家參考。具體方法分析如下:其中的1.txt,是網頁http://bbs.pediy.com/showthread.php?t=144788另存新檔1.txt具體代碼如下:import re if __name__ == "__main__": fp = open("c:\\1.txt") https = re.compile(r"(http://u.*)") for url in
本文執行個體講述了python中asyncore模組的用法,分享給大家供大家參考。具體方法如下:執行個體代碼如下:##asyncore import asyncore,socket ######################################################################## class AsyncGet(asyncore.dispatcher): """ the defined class """ #-----------
本文執行個體講述了python開啟網頁和暫停方法。分享給大家供大家參考。具體實現代碼如下:import webbrowserimport os webbrowser.open_new_tab("http://www.jb51.net/")os.system("pause")#運行windows的pause 命令,等待使用者輸入i = 0 while
本文執行個體講述了python擷取檔案版本資訊、公司名和產品名的方法,分享給大家供大家參考。具體如下:該python代碼可得到檔案版本資訊、公司名和產品名。其他的資訊都在返回的字典中。具體代碼如下: def _getCompanyNameAndProductName(self, file_path): """ Read all properties of the given file return them as a dictionary. """
本文執行個體講述了python求crc32值的方法。分享給大家供大家參考。具體實現方法如下:要想求CRC值,前面要import binasciibinascii.crc32(v) 求出了v的crc32值,這是一個long型,形如-1456387L,把這個值&0xffffffff得到的值形如48a213L的形式。然後把這個值用16進位表示出來、具體代碼如下:def _crc32(self, v): """ Generates the crc32 hash of the v.
本文執行個體講述了python實現計算資源表徵圖crc值的方法,分享給大家供大家參考。具體方法如下:實現該功能的關鍵在於解析資源資訊,找到icon的資料,然後計算這些資料的crc具體實現代碼如下: def _get_iconcrc(self, file_path): """ Generates the crc32 hash of the icon of the file. @return: str, the str value of the file's icon
scapy是python寫的一個功能強大的互動式資料包處理常式,可用來發送、嗅探、解析和偽造網路資料包,常常被用到網路攻擊和測試中。這裡就直接用python的scapy搞。這裡是arp的攻擊方式,你可以做成arp攻擊。複製代碼 代碼如下:#!/usr/bin/python"""ARP attack"""import sys, osfrom scapy.all import *if os.geteuid() != 0: print "This program must be run as
本文執行個體講述了python中list迴圈語句用法。分享給大家供大家參考。具體用法分析如下:Python 的強大特性之一就是其對 list 的解析,它提供一種緊湊的方法,可以通過對 list 中的每個元素應用一個函數,從而將一個 list 映射為另一個 list。執行個體複製代碼 代碼如下:a = ['cat', 'window', 'defenestrate']for x in a: print x, len(x)for x in [1, 2, 3]: print x, #