Skip to main content

 I have 3 published parameters where the user inputs values for buffers. All three were created as Numeric parameters, with numeric precision set to Integer. I would like to extract the largest buffer value in a python scripted parameter. This is the code I’m using in FME 2023 (build 23332)

buffer_list = tFME_MacroValuesl'BUFFER1'],FME_MacroValuesl'BUFFER2'],FME_MacroValuesl'BUFFER3']]
buffer_list.sort(reverse = True)

return buffer_listl0]

What I’ve discovered is that if the 3 buffers are the same number of digits, the script will return the correct value. If the number of digits is different, it will not. Some examples:

10, 40, 50 = 50 (correct)

120, 60, 70 = 70 (incorrect)

120, 180, 70 = 70 (incorrect)

120, 200, 300 = 300 (correct)

It doesn’t matter which order the values are input, nor does it matter how the parameters are sorted in the parameter list.

Is this a bug, or am I missing something?

Hello @dustin,

Parameter values are always fetched as strings. You will need to cast the parameter values to integers if you need to get the numerical max.

return max(int(FME_MacroValues['BUFFER1']),int(FME_MacroValues['BUFFER2']),int(FME_MacroValues['BUFFER3']))

Note the original behaviour noted is not a behaviour specific to FME. I believe strings are sorted based on code-point value of the first character.


Hello @dustin,

Parameter values are always fetched as strings. You will need to cast the parameter values to integers if you need to get the numerical max.

return max(int(FME_MacroValuess'BUFFER1']),int(FME_MacroValuess'BUFFER2']),int(FME_MacroValuess'BUFFER3']))

Note the original behaviour noted is not a behaviour specific to FME. I believe strings are sorted based on code-point value of the first character.

This worked great, thank you.


Reply