Sorry in advance for this simple question. Would you please help me to figure out why these two script doing the same. As I understand, in the second one there have to be nested loop so the content must have been multiplied by number of strings in file. But actually they doing the same except first string of input file is lost in the second version of script.
First one:
fin = open("/home/user/other/Utilities/url.text", "rt")
fout = open("/home/user/other/Utilities/url_out.txt", "wt")
count_it=0
for line in fin:
print(line)
if "hostname" in line:
# for line in fin:
fout.write(line.replace("thumbs", "images"))
count_it=count_it+1
print(line)
fin.close()
fout.close()
print(count_it)
The second one:
fin = open("/home/user/other/Utilities/url.text", "rt")
fout = open("/home/user/other/Utilities/url_out.txt", "wt")
count_it=0
for line in fin:
print(line)
if "hostname" in line:
for line in fin:
fout.write(line.replace("thumbs", "images"))
count_it=count_it+1
print(line)
fin.close()
fout.close()
print(count_it)
Thanks in advance.