Alternatively, FME String functions might be helpful. e.g.
@ReplaceRegEx(@Trim(@CurrentAttribute(),","),",{2,}",",")
I agree, it's really terrible. I think Safe is working on it, however...
Oh dear, this new <code> style formatting in the Knowledge Base is absolutely horrible...
You could also use this code:
import fmeobjects def get_attributes(feature, attr_names):    for attr_name in attr_names:     value = feature.getAttribute(attr_name)      if value:        yield value def FeatureProcessor(feature):   to_concatenate = ("buildingNumber", "throughfare", "dependantthroughfare")    # Modify as needed   result = ",".join(get_attributes(feature, to_concatenate))    # Modify as needed   feature.setAttribute("CONCATENATED", result)
I'm not a big fan of list comprehensions in this particular case, because they call feature.getAttribute() twice, which is unnecessary. This is why I created the generator function get_attributes(), which only returns the attributes with a "truthy" value.
Please be aware that if the feature attribute contains the number 0 (stored as integer or float), this value is considered to be "falsy", which means that it will not be concatenated in the result. What's worse though, is that the script will choke on the str.join() call if 1 or more attributes aren't string values (which is actually what your attribute names suggest).
To tackle both problems, you could replace the get_attributes() function with this block:
def get_attributes(feature, attr_names):    for attr_name in attr_names:     value = feature.getAttribute(attr_name)      if value not in ('', None):       yield format(value)
This will work as long as you don't have any non-ASCII characters in your attributes...
Then create an attribute for the concatenation character, like this:
And the StringConcatenator to do the magic:
I am assuming they don't want ,, when the attribute is empty/missing.
ignore the Â, that's a problem with the knowledgebase upgrade.
Put to_concatenate on a separate (indented) line from the function definition.
Either break the list comprehension line, or don't, if you do there can be nothing after it.
result = join_string.join([feature.getAttribute(attr)\ for attr in to_concatenate if feature.getAttribute(attr)])
or
result = join_string.join([feature.getAttribute(attr)for attr in to_concatenate if feature.getAttribute(attr)])
in the second case, it's all on one line.
I would expect the code to work with the following formatting
import fmeobjects def FeatureProcessor(feature):   to_concatenate = ("buildingNumber", "throughfare", "dependantthroughfare")   # Modify as needed   join_string = ","   # Modify as needed   result = join_string.join([feature.getAttribute(attr)\ for attr in to_concatenate if feature.getAttribute(attr)])   feature.setAttribute("CONCATENATED", result)
Could this be solved by replacing the PythonCaller by a StringConcatenator transformer?
That seems so much easier.
import fmeobjects
def FeatureProcessor(feature):to_concatenate = ("buildingNumber", "throughfare", "dependantthroughfare")
# Modify as needed
join_string = ","
# Modify as needed
result = join_string.join([feature.getAttribute(attr) \ for attr in to_concatenate if feature.getAttribute(attr)])
feature.setAttribute("CONCATENATED", result)
Could you please repost the script as-is, using a code block?
Here are the errors
Python Exception <SyntaxError>: unexpected character after line continuation character (<string>, line 7)
Error executing string `import<space>fmeobjects<space><space><space><lf>def<space>FeatureProcessor<openparen>feature<closeparen>:to_concatenate<space>=<space><openparen><quote>buildingNumber<quote><comma><space><quote>throughfare<quote><comma><space><quote>dependantthroughfare<quote><closeparen><space><lf>#<space>Modify<space>as<space>needed<space><space><space><space><space><lf>join_string<space>=<space><quote><comma><quote><space><lf>#<space>Modify<space>as<space>needed<space><space><space><space><space><lf>result<space>=<space>join_string.join<openparen><openbracket>feature.getAttribute<openparen>attr<closeparen><space><backslash><space>for<space>attr<space>in<space>to_concatenate<space>if<space>feature.getAttribute<openparen>attr<closeparen><closebracket><closeparen><space><space><space><lf>feature.setAttribute<openparen><quote>CONCATENATED<quote><comma><space>result<closeparen>'
Factory proxy not initialized
PythonCaller(PythonFactory): PythonFactory failed to process feature
A fatal error has occurred. Check the logfile above for details
Does it work if you separate the list comprehension into for and if components?
What error is logged?