Using Maps(aka dictionaries) while interacting Python with X++

 

We all know the excellent capabilities of using a dictionary in Python. 

A dictionary could be an indexed pair of key-value combinations, where we can have keys that necessarily not be a value that needs to start from zero. 

Ex: assigning/defining a dictionary like this:

custBal = {"CU0001": 250000.00, "CU0002": 65123.11, "CU0003": 43200.11, "CU0004": 10000.00}

It contains customer balances.

And thereby I can access the values like:

 print(custBal["CU0002"])

We can also loop through the elements by:

for x in custBal:

    print (x)

The compiler will give you Keys' values:


Or I can access the values of the keys, by simply:

print (custBal.values())

Which would result in:


Also, I can add/remove/manipulate elements by simple operations like:
del (custBal["CU0002"])

Now to the main point. Why so much ado about dictionary` data-types on Python?

Answer is simple. They behave exactly as a map datatype of x++. We can, in essence, load a map variable in x++ and pass it on to Python, to do further executions (ex: operating a Tensorflow multiprocessing, some data analysis, some data science-related staffs, etc.)   

Map CustBal = new Map(Types::String, Types::real);

while select AccountNum, CustBalanceMST from custTableBalanceView

where [<some condition is met>]

{

custBal.insert(custTableBalanceView.AccountNum, custTableBalanceView.CustBalanceMST);

}

More on this topic, coming soon. Stay tuned. 

[P.S.: I am using Spyder (Python 3.9) as my IDE, which I downloaded from: https://www.anaconda.com/products/distribution#download-section]

Comments

Popular posts from this blog

X++ : mistakes which developers commit the most

Make your menu items visible on main menu, conditionally,, using this cool feature of D365FO

Speed up your execution performance by using SysGlobalCaches