I have a text file called my_urls.txt that has 3 URLs:
example1.com
example2.com
example3.com
with open("../test_data/my_urls.txt", "r") as urlFile:
urls_list = urlFile.readline().split('\n')
print(urls_list)
['example1.com', '']
I wonder why urls_list is not giving me ['example1.com', 'example2.com', 'example3.com']
>Solution :
You need to iterate over the open file. This iterates over the lines for you:
with open("../test_data/my_urls.txt", "r") as urlFile:
urls_list = []
for url in urlFile:
urls_list.append(url.strip())
print(urls_list)