I'am really new to Python programming and I have this burning problem with changing a specific string in a text file with a strings which are stored in a list.
I'am working on media wiki documents - converting them from .doc to wiki code. After a conversion all images are replaced by a tag [[Media:]] - I want to replace all [[Media:]] tags with a names of pictures stored in a list. For example in a converted document there will be 5 [[Media:]] tags so it means that I have list like this:
li = ["image1.jpg", "image2.jpg", "image3.jpg", "image4.jpg"]
And I want to change first tag in document to bo replaced with image1.jpg, the second tag found in document with image2.jpg and so on..
Here is a piece of code, but I can not figure how to make iteration through list to work
li = ["image1.jpg ", "image2.jpg ", "image3.jpg ", "image4.jpg ", "image5.jpg "]
a = 0
src = open('sap.txt').readlines()
dest = open('cel.txt', 'w')
for s in src:
a += 1
dest.write(s.replace("[[Media:]]", li[a]))
dest.close()
I will be grateful for help
sap.txt