I just got started with Python this week and I wanted to put something together in order to solve a real-world problem.
Basically I am opening to files that contain URLs.
I want Python to go through each line of the file chosen for TOPICS and extract a certain part of a string, which is working fine.
While in the same loop, I want Python to go through each line of the file chosen for PAGES and check if a line contains the part of the string that was extracted beforehand. Once it does, I want Python to generate a certain output, which also works fine.
The only problem is that Python seems to run through the whole loop only once. So I am getting the correct output exactly one time and then the code ends.
This is the code I have written:
fi_topics = input('Enter TOPICS: ')
fi_pages = input('Enter PAGES: ')
h_topics = open(fi_topics)
h_pages = open(fi_pages)
for la in h_topics:
la = la.strip()
spos = la.find('topic/')
topic = la[spos+6:]
for lb in h_pages:
lb = lb.strip()
if topic not in lb:
continue
print( lb , 'https://www.exampleurl.com/t/'+topic )
Any hint on what could be the problem is highly appreciated!