Question
· Aug 4

Convert IRIS DynamicArray to Python list

Hello Community,

How to convert the IRIS %DynamicArray into python list. I got " <THROW>TestDyncArray+1^MyLearn.Pyth.NewClass1.1 *%Exception.PythonException <PYTHON EXCEPTION> 246 <class 'AttributeError'>: <unknown exception data>" error when passing array values to python class.

ClassMethod TestDyncArray()
{
	Do ..DyncArrayInPy([1,2,3,4])
}

ClassMethod DyncArrayInPy(numbers) [ Language = python ]
{
	import iris
	print(type(numbers)) ;<class 'iris.%Library.DynamicArray'> need to be a <class 'list'>
	for num in numbers:
		print(num)
}

Thanks!

Product version: IRIS 2024.1
$ZV: IRIS for Windows (x86-64) 2024.1 (Build 267.2U) Tue Apr 30 2024 16:41:33 EDT
Discussion (3)1
Log in or sign up to continue

First convert the dynamic array to a Cache List and then the Cache List to Python List - voila the job is done

/// Convert a dynamic array to a Cache List
/// 
ClassMethod ArrayToList(arr)
{
	q:'arr.%Size() $lb()
	s list="", it=arr.%GetIterator()
	while it,it.%GetNext(.key,.val) {
		s typ=arr.%GetTypeOf(key)
		s list=list_$case(typ,"object":$lb(val.%ToJSON()),"array":$lb(..ArrayToList(val)),"null":$lb(),:$lb(val))
	}
	q list
}