法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)
方法非原创,文责不负。嘿嘿