法1:
import glob import os os.chdir(「./」) for file in glob.glob(「*.py」): print file
法2:
for file in os.listdir(「./」): if file.endswith(「.py」): print file
法3:
for root, dirs, files in os.walk(「./」): for file in files: if file.endswith(「.py」): print os.path.join(root, file)
方法非原創,文責不負。嘿嘿url