python 3.x - Reading from subdict in python3 -
i have 2 dict. 1 local player data , 1 listing players subdictionaries:
class gamedata: def __init__(self): self.player = {'id' : 1453339642, 'positionx' : 123, 'positiony' : 0 } self.players = {1453339642: {'name' : "admin"} } gamedata = gamedata()
then print out check if works:
x in gamedata.player: print (str(x),':',gamedata.player[x]) print("\n\n") x in gamedata.players: print (str(x)) y in gamedata.players[x]: print (' ',y,':',gamedata.players[x][y]) print("\n\n")
this results in:
id : 1453339642 positiony : 0 positionx : 123 1453339642 name : admin
when want access player's id in players instance
#print(str(type(gamedata.player))) #print(str(type(gamedata.players))) print(str(type(gamedata.players[1453339642])))
i keyerror result. why?
if put in file, works:
class gamedata: def __init__(self): self.player = {'id' : 1453339642, 'positionx' : 123, 'positiony' : 0 } self.players = {1453339642: {'name' : "admin"} } gamedata = gamedata() print(str(type(gamedata.players[1453339642])))
only indentation differs code. there must happening gamedata
between instantiation , final print
.
Comments
Post a Comment