Dec-13-2021, 01:01 AM
Maybe something like this:
#! /usr/bin/env python3 import re file = 'some.txt' mylist = [] with open(file, 'r') as lines: print('----Original----') for line in lines: print(line.strip()) new_line = re.sub('whiff', 'woo', line) mylist.append(new_line) with open(file, 'w') as lines: for line in mylist: lines.write(f'{line.strip()}\n') with open(file, 'r') as lines: print() print('----New File----') for line in lines: print(line.strip())
Output:----Original----
yippe
wahoo
whiffenhard
yerp
----New File----
yippe
wahoo
wooenhard
yerp
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags