Skip to main content
Solved

Python - Even or Odd


danilo_fme
Evangelist
Forum|alt.badge.img+42

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.

View original
Did this help you find an answer to your question?

2 replies

takashi
Supporter
  • 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+43
  • Safer
  • September 1, 2016
takashi wrote:

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.

 

 


Reply


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