2013-06-13 47 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.