Solved

Python - Even or Odd

  • 31 August 2016
  • 2 replies
  • 0 views

Userlevel 5
Badge +30

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
icon

Best answer by takashi 1 September 2016, 00:29

View original

2 replies

Userlevel 3
Badge +17

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.

Userlevel 4
Badge +26

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