Edit: The title could have been more descriptive, I am sorry for that!
First time poster, frequent reader.
I am very green to both programming and python, trying my best and this board has been helpful just by reading.
Now, I have a problem of my own that I want to post.
I got a rather large .txt file (I guess?) and I have already replaced certain words
with the word "value".
Now I want to replace all the "value"'s with numbers starting from 0 .. n.
So far I got this, and it works, however it takes forever (well a few minutes but hey, that is forever!)
# -*- coding: cp1252 -*- f = open("test.txt") contents = f.read() f.close() print "Antal förekomster av value:", contents.count("value") wordcount = contents.count("value") file = open('test.txt') data = file.read() count = 0 while (count < wordcount): string = str(count) data = data.replace('value', string , 1) file = open('test.txt', 'w') file.write(data) file.close() count = count + 1 print "du är klar"
The question, how can I (if possible) replace all "value" with numbers in a quicker way then above?
Thanks for any help, tips or advice!
Edited 5 Years Ago by Lebowski: Terrible title!