Skip to main content
Question

How to deal with comma in attribute names? Use PYTHON

  • February 11, 2015
  • 2 replies
  • 104 views

Forum|alt.badge.img
Did you know commas in attribute names creates all kind of weird effects? Try the following workspace:

 

 

Creator -> attribute creator: Create "Lastname, Firstname"= 1000 -> inspector 

 

 

Everything OK there. Now add an attributeKeeper to the chain, and tell it to keep "Lastname, Firstname". Guess what? The value 1000 of your attribute "Name, Comma" goes POOF. Its value is now missing. 

 

 

Now why on earth would anyone want to have comma in attribute names? Well, it is what you get when you fetch data from a variety of sources, including XML. 

 

 

My guess is that (some) transformer will feed TCL the attribute names as arguments, and since TCL arguments are comma separated it all gets very confusing. 

 

 

Instead of the attributeKeeper you could add AttributeCopier and copy Lastname, Firstname to whatever attribute you like. AttributeCopier crashes with this error message: 

 

AttributeCopier: CopyAttributes function syntax is: @CopyAttributes([ENCODED,] ATTR_LIST_DEF_VAL, [<oldAttrName>,<newAttrName>, <default value>]+) 

 

 

Now how on earth can you deal with it? Can't use the name as is (with commas), you'd get totally unpredictable results. Cant change the name... 

 

 

Python to the resque! You can use python to copy the attribute, preferably to a name without a comma. 

 

 

Insert this python snippet into the python caller below 

 

8< - ----- 

 

import fmeobjects

 

# Template Function interface

 

def copyComma(feature):

 

    commaName = feature.getAttribute('Lastname, Firstname')

 

    if commaName:

 

        feature.setAttribute("newName", commaName)

 

 

8<--- 

 

That's it! 

 

 

    

 

 

 
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

Forum|alt.badge.img
  • Author
  • February 11, 2015
Much simpler solution: Use a BulkAttributeRenamer and Regular Expression Replace, with Text To Find = ,

 

 

takashi
Celebrity
  • February 11, 2015
Hi,

 

 

As you mentioned, there are many situations where attribute names containing commas cannot be treated as expected, in FME 2014 or earlier.

 

The issue seems to have been resolved in FME 2015, at least for the AttributeKeeper and the AttributeCopier.

 

 

Takashi