I get the following error when I run my code at the line that I marked with a #<---
:
TypeError: 'GamePlayer' object is not subscriptable
.
Apparently, not subscriptable means I don't have a certain method implemented. I don't know how this applies to my code, or how to fix it. The function second from the top is where the error occurs.
The value passed to that function is: ["b'direction:north", 'fromTime:2013-06-12 16:32:27.102400', 'fromY:0', 'fromX:0', "identity:1,'"]
(I'm not sure how to get rid of the b'
), but I'm sure it's not causing the problem.
@staticmethod
def data_line_to_dict(data):
decoded = dict()
data_peices = str(data).split(', ')
print(data_peices)
for d in data_peices:
key_val = d.split(':')
print(key_val)
decoded[key_val[0]] = key_val[1]
return decoded
@staticmethod
def create_from_data_line(data): #The value of data is: ["b'direction:north", 'fromTime:2013-06-12 16:32:27.102400', 'fromY:0', 'fromX:0', "identity:1,'"]
dictionary_data = GamePlayer.data_line_to_dict(data.strip())
p = GamePlayer()
p.set_variable('fromX', int(p['fromX'])) #<--- where error occurs
p.set_variable('fromY', int(p['fromY']))
date = datetime.datetime.strptime(p['fromTime'], '%Y-%m-%d %H:%M:%S')
p.set_variable('fromTime', data)
p.set_variable('identity', int(p['identity']))
return p
def create_data_line(self):
final = ""
for k in self.values:
v = self.values[k]
final += str(k) + ":" + str(v)
final += ", "
return final
def set_variable(self, variable, value):
self.values[variable] = value
def get_variable(self, variable):
return self.values[variable]
def get_microseconds_in_direction(self):
now = datetime.datetime.today()
diff = now - self.get_value['fromDate']
return diff.microseconds