最简单的方法是自己过滤全局结果。这是使用简单循环理解的方法:
import globres = [f for f in glob.glob("*.txt") if "abc" in f or "123" in f or "a1b" in f]for f in res: print f您也可以使用regexp而不使用
glob:
import osimport reres = [f for f in os.listdir(path) if re.search(r'(abc|123|a1b).*.txt$', f)]for f in res: print f
(顺便说一句,命名变量
list是一个坏主意,因为
list它是Python类型…)



