[Ironpython-users] Implicit conversion of objects to float

Cesar Mello cmello at gmail.com
Fri Feb 24 19:54:54 CET 2012


Hi,

We embedded IronPython to allow users to specify custom KPIs to be
calculated from plant-floor measurements. It's woking nicely. The user
selects which measurements she wants, provides aliases to these and they
get exposed to the expression scope as variables.

But we have two kinds of users:

1) People that only need the value of the measurements; they would like the
variable to be the measurement value, so they could write short expressions
like:

a + b * 0.2

2) People that want more advanced scenarios, and need more attributes of
the measurement (for example, the timestamp of the data acquisition and its
quality). For example:

(b.Value - a.Value) / (b.SourceTimestamp -
a.SourceTimestamp).TotalMilliseconds

Is there a way to satisfy both scenarios? So that the object could also be
evaluated implicitly as a float?

My first thought was to use a coercion, but the documentation does not
recommend it. Any other suggestions please?

Thank you so much for the attention.

Best regards!
Mello
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20120224/ae923ecc/attachment.html>


More information about the Ironpython-users mailing list