Apr-21-2018, 12:41 AM
This happens only when looping.
I have been looking for 3 days now, and I did not get anywhere with this.
I have a list of words that need to be placed in a URL, then print the URL on the screen.
This is what I did:
fh = open('words.txt')
for line in fh:
>>> URLa = "https://www.website.com/sub-path/XXXXX"
>>> URLb = "/some-time"
>>> Link = URLa.replace("XXXXX", line)
>>> print(Link + URLb)
fh.close()
The results of the code above is as this:
https://www.website.com/sub-path/WORD1
/some-time
It splits the URL in 2 lines, when obviously it needs to be 1 single line like this:
https://www.website.com/sub-path/WORD1/some-time
Anybody has an answer for me please?
Thanks a lot
I have been looking for 3 days now, and I did not get anywhere with this.
I have a list of words that need to be placed in a URL, then print the URL on the screen.
This is what I did:
fh = open('words.txt')
for line in fh:
>>> URLa = "https://www.website.com/sub-path/XXXXX"
>>> URLb = "/some-time"
>>> Link = URLa.replace("XXXXX", line)
>>> print(Link + URLb)
fh.close()
The results of the code above is as this:
https://www.website.com/sub-path/WORD1
/some-time
It splits the URL in 2 lines, when obviously it needs to be 1 single line like this:
https://www.website.com/sub-path/WORD1/some-time
Anybody has an answer for me please?
Thanks a lot