2013-06-13 72 views

回答

5

可以使用glob模塊:對glob.glob

import glob 
your_list = glob.glob('*.xyz') 

幫助

>>> print glob.glob.__doc__ 
Return a list of paths matching a pathname pattern. 

    The pattern may contain simple shell-style wildcards a la 
    fnmatch. However, unlike fnmatch, filenames starting with a 
    dot are special cases that are not matched by '*' and '?' 
    patterns. 
+1

'幫助(glob.glob)';) –

+0

或'ipython','glob.glob?' –

0

人們可以使用globos(我想glob更多)

from glob import glob 
file_list = glob('*.xyz') 

import os 
file_list = [i for i in os.listdir(os.getcwd()) if i.endswith('.xyz')] 

使用glob讓你不過濾結果自己,但定製filterring允許檢查複雜的規則

也應該認識到filenames starting with a dot are special cases that are not matched by '*' and '?' patterns.