Skip to main content
Solved

Noob python fme query


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
View original
Did this help you find an answer to your question?
This post is closed to further activity.
It may be a question with a best answer, an implemented idea, or just a post needing no comment.
If you have a follow-up or related question, 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
Evangelist
  • 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.

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings