Converting Indigo Lists and Dicts to Python Types
Posted: Wed Jul 15, 2020 8:27 am
I'm storing a list of dictionaries in a custom plugin device. The list is of type indigo.List() and the dictionaries are each of type indigo.Dict() based on Indigo Specific Data Types. I can't get json to work with these Indigo data types so I would like to convert the list into a local variable that is a Python list() containing items of type Python dict(). I could then use json to convert the list into a string. So two questions:
- Is there an easy way to convert indigo.List() or indigo.Dict() into a string using json?
- If not, is there any easier way than the code below to convert these Indigo data types to the Python equivalent types?
- Code: Select all
def simpleConvertIndigoToPython(self, dataType, data):
if dataType == 'list':
newData = []
for item in data:
newData.append(item)
elif dataType == 'dict':
newData = {}
for key in data.keys():
newData[key] = data[key]
return newData
- Code: Select all
pythonList = []
for item in localPropsCopy['indigoList']:
pythonList.append(self.simpleConvertIndigoToPython('dict', item))
- Code: Select all
import copy
newList = []
newList += copy.copy(indigoList)