Here's your problem -
for f,t in arr:
if 'description' not in line:
line = line.replace(f, t)
It will keep changing that line, for each value of f and t that you have in arr.
You need to break out of the for loop, or do something so that it only changes the line once.
Enalicho
Junior Poster in Training
62 posts since Aug 2011
Reputation Points: 28
Solved Threads: 13
Skill Endorsements: 0
yes I know but I can't break the loop.I need that it changes all the array.
What else can I do for changing a line once ?
This doesn't make sense. Let's say you have a file with the line
1/1/1
And your arr values were [ (1/1/1, 1/1/2), (1/1/2, 1/1/3), (1/1/3, 1/1/4) ]
Going through the for loop -
Line -
1/1/1
Replace line, line is now 1/1/2
Replace line, line is now 1/1/3
Replace line, line is now 1/1/4
This isn't what you want, so if you had instead
Line -
1/1/1
Replace line, line is now 1/1/2, break
You wouldn't be having issues.
Enalicho
Junior Poster in Training
62 posts since Aug 2011
Reputation Points: 28
Solved Threads: 13
Skill Endorsements: 0
ok but afterwards
how can I change 1/1/2 to 1/1/3 if I break after changing 1/1/1 to 1/1/2 ?
For line in file:
For f, t in arr:
If line matches current value of f, replace and break
Nothing fancy, just try to think about what your for loops are doing.
Enalicho
Junior Poster in Training
62 posts since Aug 2011
Reputation Points: 28
Solved Threads: 13
Skill Endorsements: 0