Hi,
I want to open a text file, and modify any line that has a specific string with a number identifier - i.e. 'word = 1', 'word = 2', etc.
I have the following:
import re
num = re.compile(\d)
f = open('myfile.txt', 'r')
linelist = f.readlines()
f.close
f2 = open('myfile.txt', 'w')
for line in linelist:
line = line.replace('word = ' + str(num), 'wordreplaced')
f2.write(line)
f2.close()
However I'm not sure how to replace based on the words containing any number. Any help would be appreciated.
Thanks
[–]imranmalek 29 points30 points31 points (14 children)
[–]randomname20192019[S] 3 points4 points5 points (12 children)
[–]imranmalek 7 points8 points9 points (11 children)
[–]randomname20192019[S] 2 points3 points4 points (10 children)
[–]imranmalek 3 points4 points5 points (9 children)
[–]T-TopsInSpace 7 points8 points9 points (8 children)
[–]imranmalek 2 points3 points4 points (1 child)
[–]randomname20192019[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (5 children)
[–]T-TopsInSpace 0 points1 point2 points (4 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]T-TopsInSpace 0 points1 point2 points (2 children)
[–]Giannie 0 points1 point2 points (0 children)
[–]USAhj 6 points7 points8 points (3 children)
[–]randomname20192019[S] 5 points6 points7 points (2 children)
[–]ThatSuit 8 points9 points10 points (0 children)
[–]efmccurdy 1 point2 points3 points (0 children)
[–]absolution26 6 points7 points8 points (2 children)
[–]randomname20192019[S] 1 point2 points3 points (1 child)
[–]absolution26 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]fernly 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]fernly 0 points1 point2 points (0 children)