The functions you may want are also in the os
module.
import os
dir = '/some/dir'
xml_files = [file for file in os.listdir(dir) if file.lower().endswith('.xml')]
if xml_files:
ans = input('delete XML files: %s
[y/N] ' % ', '.join(xml_files))
if ans.lower() in ('y', 'yes'):
for file in xml_files:
os.remove(os.path.join(dir, file))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…