I am having a problem using a list that is made in a function that I am iterating. My code at the moment looks like this:
def get_things(i):
html=str(site[i])
browser = webdriver.Chrome() # Optional argument, if not specified will search path.
browser.get(html);
playerlist=[]
teamlist=[]
all_players = browser.find_elements_by_xpath("//a[@class='name']")
all_teams = browser.find_elements_by_xpath("//td[@class='last']")
for a in all_players:
playerlist.append(str(a.text))
print playerlist
for td in all_teams:
teamlist.append(str(td.text))
print teamlist
browser.quit()
return playerlist, teamlist
I then want to use teamlist and playerlist in another function later in my program.
for i in xrange(0,2):
get_things(i)
print teamlist #This is where Im told teamlist doesn't exist
print playerlist #This is where I'm told playerlist doesn't exist
print_sheet(teamlist, playerlist)
Where the two print statements are for me to make sure that the program is picking up items as it should. My problem, though, is that I am told that teamlist and playerlist do not exist.
NameError: name 'teamlist' is not defined
I believe that the return statement should make these available to the rest of the program, but it is not.
How can I make these lists available to the rest of the program?