4 Python Data Components
Python data components extension is .pydcmp. Python data
components are similar to regular Python components as STML data
components are similar to regular STML components. Unfortunately,
there is no <:return:> tag in Python, nor can the Python
return statement be used (since it would be at the top
level, where it is a syntax error). So, in order to return a value
from the data component, you
raise an exception of the proper type, ReturnValue, with the
exception value being the return value. The ReturnValue exception is
preloaded into the global namespace in which the component is
executed, so it doesn't need to be imported.
For example, to return the value of the variable foobar from a data
component:
raise ReturnValue, foobar
The neat thing about this method of returning the value is that you
can raise the exception from anywhere in the data component, i.e. from
within functions, classes, wherever.
Raising other exceptions will, of course, invoke the normal error
handling routines. Raising no exception returns the value None
Setting the caching parameters of a data component is identical to that of
regular Python components.
As with normal STML data components, any generated output is ignored.