Skip to main content
Solved

Noob python fme query

  • June 25, 2014
  • 2 replies
  • 14 views

Forum|alt.badge.img+1
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.

 

Best answer by david_r

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
This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

david_r
Celebrity
  • Best Answer
  • June 25, 2014
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

Forum|alt.badge.img+1
  • Author
  • June 25, 2014
Excellent! Thanks for the clear example.