Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialleonardorubiano
9,005 PointsTypeError: 'NoneType' is not subscriptable
I have a created each team as a dictionary, with one of the keys being "members" whose initial value is an empty key. Within my member assignment function, I am trying to append a player to the "members" list for that team, but getting the aforementioned error. When I try to debug using pdb, I can see that the variables in question aren't empty variables, and manually doing team['members'].append(player) seems to work. Any thoughts as to where I might be going wrong? Full function below:
def assign_member(player, teams):
team = find_team(player, teams) # returns an available team
#import pdb; pdb.set_trace()
team['members'].append(player) # this line seems to be the issue
player['team'] = team['name']
if player['experience'] == True:
team['experienced_members'] += 1
if len(team['members']) == 6:
team['full'] = True
available_teams.remove(team)
1 Answer
Steven Parker
231,236 PointsBoy, it's sure hard to read Python without indenting! Follow the instructions below in the Markdown Cheatsheet for blockquoting code.
But it will take more of the code to reveal the problem. From what you have here, it seems that either the values being passed to assign_member or the function of find_team are causing "team" to be set to None on the first line of the function. Then, when it gets down to where it tries to subscript team with 'members', you see the error.
leonardorubiano
9,005 Pointsleonardorubiano
9,005 PointsHi Steven,
Thanks for your answer! I'll look into it a bit more. And I hadn't seen the Markdown sheet, I'll definitely use it in the future.
leonardorubiano
9,005 Pointsleonardorubiano
9,005 PointsThe issue was with the find_team function; I need to rethink how to return an appropriate team.