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

2021-04-25 08:32:03 字數 1306 閱讀 2614

>>> 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 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://command.com', '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.com', '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

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...

框架學習四 1 處理OOM之LazyList

一 簡介 優點 簡潔,用起來方便。缺點 貌似不更新了。也不算缺點。二 位址和支援的版本 支援版本 2.0 三 用法 定義乙個imageloader例項,然後呼叫其displayimage 即可,最後記得清除快取。imageloader imageloader new imageloader cont...

python3 處理檔案

fhand open text.txt python裡面的open 函式返回乙個file handler,如果你print fhand 的話,得到一些跟檔案有關的資訊 name text.txt mode r encoding us ascii 今天實現了乙個讀取每一行,分別輸出並統計行數的功能 f...