Posted by RlS
Trigon

TypeError: string indices must be integers

I need a way to get all the device data at one time in python. Here is what I am using so far'

for k in dictData.items():
print(dictData['devices'][0]['device_id'][k]) #TypeError: string indices must be integers
print(dictData['devices'][1]['alias'][k])

I also tried this
print(dictData['devices'][1]['alias'][0:5])

No go.

Thanks in advance and apologies for the earlier confusion!

1 Accepted Solution

Accepted Solutions
Posted by DomLan
Heptagon
Solution

Re: TypeError: string indices must be integers

for key, value in dictData.items(): 
for idx, x in enumerate(value):
print("Remote Control is {} for item {}".format(x["remotecontrol_id"], idx))
print("Device ID is {} for item {}".format(x["device_id"], idx))
print("Alias is {} for item {}".format(x["alias"], idx))
print("GroupId is {} for item {}".format(x["groupid"], idx))
print("OnLine state is {} for item {}".format(x["online_state"], idx))

 

Regards

Domenico Langone
MCSD: App Builder

View solution in original post

2 Replies
Posted by DomLan
Heptagon
Solution

Re: TypeError: string indices must be integers

for key, value in dictData.items(): 
for idx, x in enumerate(value):
print("Remote Control is {} for item {}".format(x["remotecontrol_id"], idx))
print("Device ID is {} for item {}".format(x["device_id"], idx))
print("Alias is {} for item {}".format(x["alias"], idx))
print("GroupId is {} for item {}".format(x["groupid"], idx))
print("OnLine state is {} for item {}".format(x["online_state"], idx))

 

Regards

Domenico Langone
MCSD: App Builder

View solution in original post

Highlighted
Posted by RlS
Trigon

Re: TypeError: string indices must be integers

Thanks!! That does it