用glob模块,指定后缀.dat,即可。
import globdir = '\home\your_data_file\'for f in glob.glob(dir + '*.dat'): contents = open(f,'r').read()