Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
iterating over files
#1
Hello all, I think I need a lot of help.
I have a file named CONFIG.inp. What I need to do is to create 100 others (i.e. CONFIG1, CONFIG2, etc) replacing just one thing in CONFIG.inp.

One of my problems is: in the replace method I would like to replace 'a' with b, c, d or e one in each file but of course, it will be replaced with 'names'.
And the other problem is: how could I create the CONFIG1, CONFIG1, CONFIG3 and CONFIG4 output files?. I only manage to do it just for one file.
Thank you very much.
clara

I show you what I think I should do (only with 4):
a=['b','c','d','e']
for names in a:
    s=open('CONFIG.inp').read()
    s=s.replace('a','names')
    f=open('CONFIG.inp','w')
    f.write(s)
    f.close()
Reply


Messages In This Thread
iterating over files - by clarablanes - Aug-29-2018, 05:57 PM
RE: iterating over files - by buran - Aug-29-2018, 07:05 PM
RE: iterating over files - by clarablanes - Aug-29-2018, 07:55 PM
RE: iterating over files - by buran - Aug-29-2018, 08:17 PM
RE: iterating over files - by clarablanes - Aug-30-2018, 08:55 AM
RE: iterating over files - by Gribouillis - Aug-29-2018, 08:30 PM
RE: iterating over files - by buran - Aug-30-2018, 09:25 AM
RE: iterating over files - by clarablanes - Aug-30-2018, 09:32 AM
RE: iterating over files - by buran - Aug-30-2018, 09:40 AM
RE: iterating over files - by Gribouillis - Aug-30-2018, 09:51 AM
RE: iterating over files - by clarablanes - Aug-30-2018, 09:59 AM
RE: iterating over files - by Gribouillis - Aug-30-2018, 12:16 PM
RE: iterating over files - by clarablanes - Aug-30-2018, 12:32 PM
RE: iterating over files - by buran - Aug-30-2018, 12:34 PM
RE: iterating over files - by clarablanes - Aug-30-2018, 12:43 PM
RE: iterating over files - by buran - Aug-30-2018, 12:51 PM
RE: iterating over files - by Gribouillis - Aug-30-2018, 01:53 PM
RE: iterating over files - by clarablanes - Aug-30-2018, 02:18 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Iterating Large Files Robotguy 10 5,253 Jul-22-2020, 09:13 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020