Append your results to a list, and then return that list.
def sbo_extra_dwn(link, name):
results = []
sbo_url_dwn = link + name + ".info"
sbo_url_dwn = sbo_url_dwn.replace("repository", "slackbuilds")
f = urllib2.urlopen(sbo_url_dwn)
read_page = f.read()
for line in read_page.splitlines():
if line.startswith(' '):
line = line[10:-1]
if line.startswith('http'):
results.append(line)
return results
However, you might want to return a tuple because of their immutability (suggested by @Moe):
def sbo_extra_dwn(link, name):
results = ()
sbo_url_dwn = link + name + ".info"
sbo_url_dwn = sbo_url_dwn.replace("repository", "slackbuilds")
f = urllib2.urlopen(sbo_url_dwn)
read_page = f.read()
for line in read_page.splitlines():
if line.startswith(' '):
line = line[10:-1]
if line.startswith('http'):
results = results+(line,)
return results
In your 1st example, you are print
ing the result. In the 2nd one, you are return
ing. The return
statement is pretty much like a break
, only that it returns a value too. Thus, when you return the first value, it breaks from the function.