Hi, I need to search through a given file and find certain keys and replace them, in this case it's the symbol "%". I'm not sure how to go about this.
# numbers.txt=
1234435%3574357 34763736%474526 435151463267%23 943249023403478 234724234782347 234234247824273 423478235%47283 40723840%472347 234023742%72304 372104%472389%4 7204
47242%742047239 472947247239042 7472482%7429472 4728904273%34%
21211212122121% 1121212121%6767 6767676767%8787 8787878787%
I can print the file out like this but I need to replace the 1st, 5th & 13th "%" with "$".
I tried to do something like this to see if it would just find "%" but it didn't work:
^ gets error message because the .split puts it into a list. I also tried re.search("%").
Any suggestions?
Code:
f = open("numbers.txt","r")
contents = f.read( )
# I'm not sure why the .split is in here but someone suggested it to me so I
# included it. I could .split("%") but then what?
fields = contents.split(",")
print fields
# numbers.txt=
1234435%3574357 34763736%474526 435151463267%23 943249023403478 234724234782347 234234247824273 423478235%47283 40723840%472347 234023742%72304 372104%472389%4 7204
47242%742047239 472947247239042 7472482%7429472 4728904273%34%
21211212122121% 1121212121%6767 6767676767%8787 8787878787%
I can print the file out like this but I need to replace the 1st, 5th & 13th "%" with "$".
I tried to do something like this to see if it would just find "%" but it didn't work:
Code:
f = open("numbers.txt","r")
contents = f.read( )
data = contents.split(",")
if data.find("%"):
print "Symbol found"
Any suggestions?
Comment