[SAGA-RG] SAGA attributes as Python dictionaries?

Mathijs den Burger mathijs at cs.vu.nl
Wed Nov 4 09:48:21 CST 2009


Hi all,

For the Python language bindings, we (at the VU) are thinking about
CCT's idea to use the Python 'dict' interface for SAGA attributes. While
we like the idea to use Python-specific constructs in the language
bindings, it seems that SAGA attributes differ in semantics from the
'associative arrays' that are Python's dictionaries.

Some examples where Python dicts and SAGA attributes differ:

1. They throw different exceptions (e.g. KeyError vs BadParameter /
PermissionDenied / DoesNotExist / AuthenticationFailed /
AuthorizationFailed / BadParameter / IncorrectState / NoSuccess)

2. Removing SAGA attributes is permanent (AFAIK when talking to Ceriel),
while a deleted dict item can be re-added latter

3. Dictionaries accept any hashable object, whereas SAGA attributes only
accept a set of defined values.

Exposing SAGA attributes as a dictionary may therefore lead to
confusion, as the two are similar but not identical.

Another option for easy access (which we use in our implementation on
top of Java SAGA) is to use Python's 'property' construct for each
defined attribute. This allows you to do, for example:

>>> from saga import job
>>> js = job.JobDescription()
>>> js.Executable = "/bin/date"
>>> js.Arguments = [ "-R" ]

Python translates such property access to calling getter an setter
functions that can do additional checking. Very flexible, and the syntax
is even shorter than using the 'dict' interface. Wouldn't that be a
better option for easy access to SAGA attributes in Python?

best,
Mathijs




More information about the saga-rg mailing list