Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
iterating over files
#2
please, show what your CONFIG.inp file looks like and what the expected output is (one file)
did you check configparser module and can you use it? i.e. is your file compatible with a format that configparser can read?
names = ['b','c','d','e']
with open('CONFIG.inp') as f:
    current_config = f.read()
for i, name in enumerate(names, start=1):
    new_config = current_config.replace('a', name)
    with open(f'COFIG{i}.inp', 'w') as f:
        f.write(new_config)
untested, but should work for python 3.6+
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

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,355 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