I made a Python script, that reads a text file then goes to a url, and adds the extension in the text file to the url. The problem is the script keeps stopping before it is done reading the file. I cant figure out why.
import urllib
f = open("extension/1.txt", 'r')
for x in f.readline():
a = f.readline()
url = "http://www.link.com/whatever/%s" % a
print url
urllib.urlretrieve(url, a)
By calling
for x in f.readline():, you’ll be going through thestringthat is the first line of the file as an iterable and then grabbing a new line for each character in the first line viaa = f.readline(). I don’t think this is your intent.The
fileobjectfis iterable itself, so you can simply do the following: