本文執行個體講述了python訪問系統內容變數的方法。分享給大家供大家參考。具體如下:#--------------------------------# Name: enviroment_variables.py# Author: Kevin Harris# Last Modified: 02/13/04# Description: This Python script demonstrates # how to acces enviroment
本文執行個體講述了python建立和刪除目錄的方法。分享給大家供大家參考。具體分析如下:下面的代碼可以先建立一個目錄,然後調用自訂的deleteDir函數刪除整個目錄#--------------------------------------# Name: create_directory.py# Author: Kevin Harris# Last Modified: 02/13/04# Description: This Python script
本文執行個體講述了python實現根據ip地址反向尋找主機名稱的方法。分享給大家供大家參考。具體如下:import sys, sockettry: result = socket.gethostbyaddr("66.249.71.15") print "Primary hostname:" print " " + result[0] # Display the list of available addresses #that is also returned print
python將字串轉換成數組的方法。分享給大家供大家參考。具體實現方法如下:#-----------------------------------------# Name: string_to_array.py# Author: Kevin Harris# Last Modified: 02/13/04# Description: This Python script demonstrates # how to modify a string by#
Python的內建模組itertools提供了非常有用的用於操作迭代對象的函數。首先,我們看看itertools提供的幾個“無限”迭代器:>>> import itertools>>> natuals = itertools.count(1)>>> for n in natuals:... print n...123...因為count()會建立一個無限的迭代器,所以上述代碼會列印出自然數序列,根本停不下來,只能按Ctrl+C退出。cycle()會把傳入的一個序列無限重複下去:>>>
本文執行個體講述了python中迭代器(iterator)用法。分享給大家供大家參考。具體如下:#---------------------------------------# Name: iterators.py# Author: Kevin Harris# Last Modified: 03/11/04# Description: This Python script demonstrates how to use iterators.#-----------------