Skip to main content
Hi,

 

 

I have a reader (esri shape) where the feature type is named 'test'. This has 2 attributes: 'price', 'quantity'.

 

How would you use the python caller to create a create a new attribute 'SalesRevenue' which contained price multiplied by quantity for each feature in test?

 

 

I know you can do the same thing using the ExpressionEvaluator but I want to know how this can be done in the python caller.

 

Hi,

 

 

here's a small example:

 

 

 

 

The code:

 

 

---

 

import fmeobjects

 

 

def getSalesRevenue(feature):

 

    unit_price = float(feature.getAttribute('price'))

 

    no_units = int(feature.getAttribute('quantity'))

 

    revenue = unit_price * no_units

 

    feature.setAttribute('SalesRevenue', revenue)

 

---

 

 

David
Excellent! Thanks for the clear example.

 


Reply