I'm trying to generate 1000 new files from already existing 1000 files in a folder named as 'mdp' into a new folder 'mdb', changing couple of lines in each of the original 1000 files. I took some help from overflow and @bruno desthuilliers suggested me to use this particular code but it hasn't worked yet and it says dest.write(line) AttributeError: 'str' object has no attribute 'write'. I'm kind of new to programming. Could anyone please tell me what am I missing?
import os
sourcedir = "/home/abc/xyz/mdp/"
destdir = "/home/abc/xyz/mdb/"
for filename in os.listdir(sourcedir):
if not filename.endswith(".mdp"):
continue
source = os.path.join(sourcedir, filename)
dest = os.path.join(destdir, filename)
fin = open("/home/abc/xyz/mdp/md_1.mdp")
fout = open("/home/abc/xyz/mdb/md_1.mdp", "w")
for line in source:
line = line.replace('integrator = md', 'integrator = md-vv')
line = line.replace('dt = 0.001', 'dt =
-0.001')
dest.write(line)
finvar instead ofsource