Skip to main content
Solved

Problem with AttributeCreator, Python parameter with space


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!

Best answer by david_r

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
View original
Did this help you find an answer to your question?
<strong>This post is closed to further activity.</strong><br /> It may be a question with a best answer, an implemented idea, or just a post needing no comment.<br /> If you have a follow-up or related question, please <a href="https://community.safe.com/topic/new">post a new question or idea</a>.<br /> If there is a genuine update to be made, please contact us and request that the post is reopened.

10 replies

david_r
Celebrity
  • February 25, 2014
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

gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • February 25, 2014

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

  • Author
  • February 25, 2014
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".

  • Author
  • February 25, 2014
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_MacroValues['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.

david_r
Celebrity
  • February 25, 2014
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

  • Author
  • February 25, 2014
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

  • Author
  • February 25, 2014
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)

 


david_r
Celebrity
  • Best Answer
  • February 25, 2014
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

  • Author
  • February 25, 2014
Thanks David,

 

 

I submitted this to Safe support, and in the meantime I will use the StringConcatenator as a workaround.

Forum|alt.badge.img
  • February 26, 2014
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.

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings