Skip to main content
Solved

Python - Even or Odd

  • August 31, 2016
  • 2 replies
  • 27 views

danilo_fme
Celebrity
Forum|alt.badge.img+51

Hello Users,

Attached the Workspace with the transformer PythonCaller. This transformer receive the attributes from Souce Data ( list values ) and generate two new Attributes to each list value : initial and final. This is Works fine.

 

So now i need to create 4 news attributes to each list values: Initial_even, End_even, Initial_odd and End_odd. For example to list 1: Inicial: 0 Final: 40 How it be: Initial_even:0 End_even: ( Initial_even.list1{} + attribute lenght this list ( int(listaTamanhoTrecho[controle] )) = 40 Initial_odd: ( Initial_even.list1{} + 1 ) = 1 End_odd: ( End_even.list1{} + 1 ) = 41

 

To list 2 Initial_even: ( End_even.list1{} + 2 ) = 42 End_even: ( Initial_even.list2{} + attribute lenght this list ( int(listaTamanhoTrecho[controle] )) = 126 Initial_odd: ( Initial_even.list2{} + 1 ) = 43 End_even: ( End_even.list2{} + 1 ) = 127

 

To list 3 Initial_even: ( End_even.list2{} + 2 ) = 128 End_even: ( Initial_even.list3{} + attribute lenght this list ( int(listaTamanhoTrecho[controle] )) = 255 *** How this value is odd, is necessary to transform to even value: +1 = 256 Initial_odd: ( Initial_even.list3{} + 1 ) = 129 End_odd: ( End_even.list3{} + 1) = 257

 

Thanks

Best answer by takashi

Hi @danilo_inovacao, sorry I'm completely unclear the requirement. What are the 'list 1', 'initial_even.list1{}', 'End_even.list1{}', etc. in your description? Does the 'attribute length' mean the number of characters of the attribute value?

If you are just looking for a way to determine if an integer is even or odd, divide the number by 2 and then see if the reminder is 0 or 1. The % operator is helpful.

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

takashi
Celebrity
  • Best Answer
  • August 31, 2016

Hi @danilo_inovacao, sorry I'm completely unclear the requirement. What are the 'list 1', 'initial_even.list1{}', 'End_even.list1{}', etc. in your description? Does the 'attribute length' mean the number of characters of the attribute value?

If you are just looking for a way to determine if an integer is even or odd, divide the number by 2 and then see if the reminder is 0 or 1. The % operator is helpful.


mark2atsafe
Safer
Forum|alt.badge.img+58
  • Safer
  • September 1, 2016

Hi @danilo_inovacao, sorry I'm completely unclear the requirement. What are the 'list 1', 'initial_even.list1{}', 'End_even.list1{}', etc. in your description? Does the 'attribute length' mean the number of characters of the attribute value?

If you are just looking for a way to determine if an integer is even or odd, divide the number by 2 and then see if the reminder is 0 or 1. The % operator is helpful.

There's even a ParityFilter on the FME Store that will test for odd/even values of integers.