Python相關模組學習1 處理檔名模組glob

2021-03-31 08:56:30 字數 1114 閱讀 3999

name

glob - filename globbing utility.

file

d:/python24/lib/glob.py

functions

glob(pathname)

return a list of paths matching a pathname pattern.

the pattern may contain ****** shell-style wildcards a la fnmatch.

data

__all__ = ['glob']

它的主要方法就是glob,用它在指令碼中處理一批檔名非常方便,示例如下:

>>> glob.glob("c://")

['c://']

>>> glob.glob("c://*")

['c://arcldr.exe', 'c://arcsetup.exe', 'c://boot.ini', 'c://bootfont.bin', 'c://cmd.txt', 'c://***mand.***', 'c://config.sys', 'c://debug_trace.txt', 'c://devtools', 'c://dfimb.dat', 'c://documents and settings', 'c://intel', 'c://io.sys', 'c://msdos.sys', 'c://msocache', 'c://ntdetect.***', 'c://ntldr', 'c://pagefile.sys', 'c://program files', 'c://recycled', 'c://recycler', 'c://response.txt', 'c://rt', 'c://suhdlog.dat', 'c://system volume information', 'c://useprint.bat', 'c://videorom.bin', 'c://windows', 'c://wmpub', 'c://wutemp']

>>> glob.glob("c://*.txt")

['c://cmd.txt', 'c://debug_trace.txt', 'c://response.txt']

從示例可以看出,它支援檔案萬用字元方式獲得檔名列表。是不是很方便

Python相關模組學習1 處理檔名模組glob

import glob dir glob all builtins doc file name fnmatch glob glob1 has magic magic check os re help glob help on module glob name glob filename globbi...

python標準模組學習1

fnmatch模組是pythhon自帶的模組,其主要功能是通過模式來匹配檔名 介面函式呼叫為 fnmatch.fnmatch file,patten patten的匹配模式為shell模式 當我們檢視其原始碼的時候,fnmatch其實是呼叫了fnmatchcase函式去處理檔名和匹配模式,該函式會做...

Python學習之路(5)模組 1

path os.getcwd 呼叫os下的getcwd print path 列印當前指令碼所在路徑 from math import sqrt 僅匯入math模組的sqrt函式 print sqrt 2 輸出 1.4142135623730951 from math import sqrt as ...

python 時間相關模組

import time 目前開發中用時間標準時間 utc time.time 當前時間戳 1970 1 1到現在的秒數 c time.time print time.gmtime c time.struct time tm year 2018,tm mon 4,tm mday 25,tm hour ...

Python 時間相關模組

時間相關的模組主要有以下幾種使用場景 日誌管理必然會記錄時間 統計程式執行開始 結束時間 測試一個函式的執行時長 time 模組提供兩種時間表達方式 假定一個零點基準,偏移長度換算為按秒的數值型 由9個整陣列成的元組 struct time 表示的時間 當前時間浮點數import time 返回時間...