Monica Monica - 6 months ago 25
Python Question

Renaming files with two different extension

I'd like to rename files in the current directory with the *.inp and *out extensions

#!/usr/bin/env python
import glob
import os

for namefile in glob.glob('*.inp'):
new_namefile = namefile.replace('dim', 'mon')

os.rename(namefile, new_namefile)

How can I rename files *.inp and *.out at the same time?

from glob import glob
for namefile in glob('*.inp')+glob('*.out'):