Article
· Apr 24, 2023 3m read

Embedded Python access to Multidimensional Properties

Multidimensional properties can be found on certain classes.

These operate as a collection of values much like a Python dictionary.

Examples of properties that might be encountered:

Class Property Description
%Net.HttpRequest Params Name value pair of form parameters
%Net.HttpResponse Headers

HTTP Headers returned with web content returned:

  • HTTPHeaders
  • EnsConfigName
  • Params
  • Content-Type
  • ResponseCode 
%Library.AbstractStream Attributes Name of originating file from FTP or mounted File system
%Library.AbstractResultSet Data Data Values indexed by query output Column name
%CSP.Request Data URL and Form Data

The class definition activates this behavior by using the Multidimensional keyword.

Property Data As %String [ MultiDimensional ];

The PyHelper was enhanced to interact with object multidimensional properties with the following additional methods:

  • MultiGet - Retrieve the simple value or default from root or sub-key of multidimensional property
  • MultiSet - Set the value of multidimensional property at root or sub-key
  • MultiKeys - Return a Python list of keys at property root or sub-key
  • MultiReplace - Replace the whole property data or a sub-key with a python dictionary
  • MultiMerge - Merge a python dictionary to root multidimensional property or sub-key
  • MultiDel - Delete whole multidimensional property data or just a subkey

 

Example: MultiGet

Arguments:

  • object reference
  • property name
  • default if not found
  • key args - one or more strings

Retrieve Filename associated with stream object

> iris.cls("alwo.PyHelper").MultiGet(stream,"Attributes",None,"Filename")

Retrieve Header associated with %Net.HttpResponse object

> iris.cls("alwo.PyHelper").MultiGet(response,"Headers",None,"content-type")

Attempting to retrieve an undefined data node and returning Python None type

> iris.cls("alwo.PyHelper").MultiGet(stream,"Attributes",None,"Unknown")
None

 

Example MultiSet

Assign simple value to Path in Multidimensional Property
Arguments:

  • object reference
  • property name
  • value to assign
  • key args - one or more sub-key names
> iris.cls("alwo.PyHelper").MultiSet(shopper,"Basket",12,"Items","Fruit","apples")

is equvalent to objectscript:

set shopper.Basket("Items","Fruit","apples")=12

 

Example MultiKeys

Returns List of Key names at path in Multidimensional Property
Arguments:

  • object reference
  • property name
  • key args - one or more sub-key names

For property content:

Basket("Items","Fruit","apples")=12
Basket("Items","Baking","eggs")=18
Basket("Items","Baking","flour")=1
Basket("Items","Cereal","oats")=1

This could return a python list of Keys under the multidimensional property key items:

> iris.cls("alwo.PyHelper").MultiKeys(shopper,"Basket","Items")
['Baking', 'Cereal','Fruit']

 

Example MultiReplace

Replace the multidimensional property data with a python dictionary content, optionally at a particular key location.
Arguments:

  • object reference
  • property name
  • dict to assign
  • key args - optional one or more sub-key names

For property content

Basket("Items","Fruit","apples")=12
Basket("Items","Baking","eggs")=18
Basket("Items","Baking","flour")=1
Basket("Items","Cereal","oats")=1

Replace the "Fruit" content

toReplace={'apples':10, 'pears':3, 'oranges':4}
> iris.cls("alwo.PyHelper").MultiReplace(shopper,"Basket",toReplace, "Items","Fruit")

 

Example MultiMerge

Merges content of python dict with existing multidimensional property content
Arguments:

  • object reference
  • property name
  • dict to assign
  • key args - optional one or more sub-key names

For property content

Basket("Items","Fruit","apples")=12
Basket("Items","Baking","eggs")=18

Merge basket dict to property

toAdd={'Baking':{'flour':1},'Cereal':{'oats':1}}
iris.cls("alwo.PyHelper").MultiMerge(shopper,"Basket",toAdd,"Items")

 

Example MultiDel

Delete ALL or part of a Multidimensional Property content
Arguments:

  • object reference
  • property name
  • key args - optional one or more sub-key names

Clear the basket property of everything

iris.cls("alwo.PyHelper").MultiDel(shopper,"Basket")

Clear just the cereal from the basket

iris.cls("alwo.PyHelper").MultiDel(shopper,"Basket","Items","Cereal")

 

Conclusion

Hope this article helps inspire new ideas and discussion for embedded Python suggestions.

Discussion (0)1
Log in or sign up to continue