Inspirel banner

Programming Distributed Systems with YAMI4

3.6.5 Python

Reading existing entries of fundamental types is straightforward:

age = params["age"]

Strings can be similarly extracted with a single operation:

first_name = params["first_name"]

Binary buffers are handled with the bytes type in Python 3.x, but in Python 2.x a special wrapper type is provided. In both cases the entry can be read in the same way, but the wrapper type in Python 2.x will refer to the actual data via its value component:

song_buffer = params["favorite_song"]

# for Python 2.x:
actual_value = song_buffer.value

Extracting arrays of fundamental types is very similar to handling of binary buffers - a reference to the internal list is returned. Arrays of boolean, integer, long, double, string and binary types are handled in the same way and in all these cases the user gets access to the internally managed list object.

For example:

my_numbers = params["favorite_numbers"]
friends = params["friends"]

Nested parameters can be extracted in a similar way:

nested = params["address"]

Note:

If the entry given by name does not exist, each of the reading operations will raise the KeyError exception. Code that needs to read entries that might not exist should rely on the built-in ``in'' operator to check whether the given entry exists or not before attempting reading it.