Skip to main content
Hi all,

 

 

I have a set of CSV files that I'm trying to parse, and they each contain several lines of metadata before the actual CSV-formatted data. I'd like to add the metadata as new attributes to each feature that I parse out using the CSV reader.

 

 

Currently I'm using a set of Python scripted parameters to open the file and parse out each line of metadata into its own parameter, then using the AttributeCreator transformer to create the new attributes and assign the parameter values. This works great except when the parameter contains a space, in which case the parameter is never assigned to the new attribute. I can work around it by having Python replace spaces with underscores, but I'd prefer to keep the spaces if possible.

 

 

Is there a better way to handle this kind of situation? Is this a bug that may be fixed in a newer version (I'm on 2013 SP1)?

 

 

Thanks!
Hi,

 

 

can you please tell / show us how you're using the AttributeCreator?

 

 

As a general rule, I always try to avoid spaces in attribute or field names.

 

 

David

Do you use regexp for parsing?

 

Then u have to escape the spaces, probalby.

 

>\\d\\w\\s]* would do any combo of digits, wordcharacters and spaces for instance.

 

 

I'm guessing it's the parsing that fails on spaces (?)

 

 

 

Gio
As an example, one of the attributes is:

 

 

Attribute Name: owner

 

Value: $(owner)

 

 

where $(owner) is the name of the Python scripted parameter. I don't have any spaces in the attribute names, just sometimes in the attribute values -- for example, $(owner) could be "John Doe".
Gio:

 

 

I'm not using regexp, I'm just reading the full line for each parameter. Here's an example of my parsing code:

 

 

path = (FME_MacroValuesl'SourceDataset_CSV'])

 

 

f = open(path, "rb")

 

 

owner = f.readline().strip()

 

f.close()

 

 

#print owner

 

return owner

 

 

If I uncomment the print statement, it prints correctly, so it seems like the Python code is working. It only fails when I try to assign it using the AttributeCreator.
Hi,

 

 

I'm surprised to hear this, as this is something I do rather frequently.

 

 

I just tested in FME 2013 SP4 and it works as it should:

 

 

 

 

David
David,

 

 

I just tried reproducing your workspace and I'm getting the same result as before:

 

Attribute(encoded: utf-8)         : `owner' has value `'

 

 

Maybe this is a bug with 2013 SP1? I will try updating to a newer version and see if that makes a difference.

 

 

Thanks for your help,

 

-Matt
Well this is strange...

 

 

I installed FME Desktop 2014, and assigning the parameters is mostly working correctly now.

 

 

However, it's still acting strange for a few that have parentheses in the parameter value, where it removes all the spaces inside the parentheses for some reason:

 

 

Attribute(encoded: utf-8)         : `proj_dir_url' has value `Not Available (coordinatefilesarelocalinsteadofinprojectdirectory)'

 

 

When I print the value from Python I get the correct formatting:

 

 

Not Available (coordinate files are local instead of in project directory)

 


That is indeed strange.

 

 

Was able to reproduce it myself using FME 2014, both using the AttributeCreator and the AttributeRenamer. However, the StringConcatenator works...

 

 

 

 

Sounds like a bug, consider forwarding it (together with a minimal workspace to reproduce) to Safe support.

 

 

David
Thanks David,

 

 

I submitted this to Safe support, and in the meantime I will use the StringConcatenator as a workaround.
We've confirmed the issue support and have filed a task with our development team to have a look at this issue. I'll try to notify the group when this is resolved.

Reply