Home
Categories
Dictionary
Glossary
Download
Project Details
Changes Log
What Links Here
FAQ
License

Python modules types limitations



Depending on the Python executable version, there are two ways of exchanging data between Java and Python UDP modules:
  • For Python version up to 2.5, there is not JSON library included in the Python implementation, so the exchange of Data is performed using a simple raw text format. With this format, there are some limitations on the types which can be exchanged with Python modules
  • For Python 2.6 and later, there is a JSON library included in the Python implementation, so the exchange of Data is performed using JSON. With this format, there are no limitations on the types which can be exchanged with Python modules
This means that there are limitations only for Python UDP modules.

Types limitation for Python up to 2.5

There are some limitations on the types which can be exchanged with Python modules.

Simple types

To access a simple type, you just have to get the Service and the value for the data name. For example, with the following Service definition:
      <publish name="myService" >
         <data name="count" type="int" />
         <data name="selected" type="bool" />
      </publish>
We could have in the Python script:
      def subscribe(self, pythonUtils):
        service = pythonUtils.getService("myService")
        countValue = service["count"]
        selectedState = service["selected"]

Structure types

Structure datas are of the Python dict type.

To access a structure, you have to get the Service, the data, and the value for the field name.

Examples

The following examples consider the following Service definition:
      <publish name="myService" >
         <data name="myStruct" type="struct" />
      </publish>
and:
      <types>
         <simpleType name="int" desc="the base int type" baseType="int" />
         <simpleType name="bool" baseType="bool" />
         <structType name="struct">
            <field name="count" type="bool" />
            <field name="selected" type="int" />
         </structType>
      </types>

Accessing a structure

Suppose we want to get the values of myStruct fields. We could have in the Python script:
      def subscribe(self, pythonUtils):
        service = pythonUtils.getService("myService")
        myStruct = service["myStruct"]
        countValue = myStruct["count"]
        selectedState = myStruct["selected"]

Setting a structure value

Suppose we want to change the fields values of myStruct fields. We could have in the Python script:
      def subscribe(self, pythonUtils):
        service = pythonUtils.getService("myService")
        myStruct = service["myStruct"]
        myStruct["count"] = 2
        myStruct["selected"] = True
As a structure is a Python dict, we could also perform:
      def subscribe(self, pythonUtils):
        service = pythonUtils.getService("myService")
        myStruct = {'count': 2, 'selected': True}
        service["myStruct"] = myStruct

Array types

Array datas are of the Python list type.

To access an array, you have to get the Service, and the array data.

Examples

The following examples consider the following Service definition:
      <publish name="myService" >
         <data name="myArray" type="array" />
      </publish>
and:
      <types>
         <simpleType name="int" desc="the base int type" baseType="int" />
         <arraytType name="array" type="int" />
      </types>

Accessing an array

Suppose we want to get the values of myArray elements. We could have in the Python script:
      def subscribe(self, pythonUtils):
        service = pythonUtils.getService("myService")
        myArray = service["myArray"]
        firstValue = myArray[0]

Setting an array value

Suppose we want to change the values of myArray elements. We could have in the Python script:
      def subscribe(self, pythonUtils):
        service = pythonUtils.getService("myService")
        myArray = service["myArray"]
        myArray[0] = 2
As an array is a Python list, we could also perform:
      def subscribe(self, pythonUtils):
        service = pythonUtils.getService("myService")
        myArray = [1, 2, 3]
        service["myArray"] = myArray

Map types

Map datas are of the Python dict type.

Examples

The following examples consider the following Service definition:
      <publish name="myService" >
         <data name="myMap" type="map" />
      </publish>
and:
      <types>
        <simpleType name="string" baseType="string" />
        <simpleType name="int" baseType="int" />
        <mapType name="map" keyType="string" valueType="int" />
      </types>

Accessing a map

Suppose we want to get the values of myMap elements. We could have in the Python script:
      def subscribe(self, pythonUtils):
        service = pythonUtils.getService("myService")
        myMap = service["myMap"]
        for key, v in myMap.items():
        # do something with the values

See also


Categories: concepts | python

Copyright 2017-2020 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v3 licence