I am trying to access each row of the excel data I read with pythoncaller. How can I do that
coulumnData = feature.getAttribute('Column1') data = str(coulumnData).split() for row in data: print(row)
and how do I read FLOAT values as well?
I do not understand what kind of object is returned by feature.getAttribute. If I print coulumnData, it is printed nicely row by row. But, how do I access those row of data? I want to do something like
coulumnData = feature.getAttribute('Column1') data = str(coulumnData).split() print(data[10])
Best answer by david_r
When I try to do this:
coulumnData = feature.getAttribute('Column1') for row in coulumnData: print(row)
I get this error:
The PythonCaller is called once for each row in your Excel, meaning you cannot access all rows by the column name. You'll have to add them up yourself, e.g.
import fme import fmeobjects
class FeatureProcessor(object):
def __init__(self): """Base constructor for class members.""" self.column1_values = list()
def input(self, feature): """This method is called for each FME Feature entering the PythonCaller. If knowledge of all input Features is not required for processing, then the processed Feature can be emitted from this method through self.pyoutput(). Otherwise, the input FME Feature should be cached to a list class member and processed in process_group() when 'Group by' attributes(s) are specified, or the close() method.
:param fmeobjects.FMEFeature feature: FME Feature entering the transformer. """ value = feature.getAttribute('column1') if value is not None: self.column1_values.append(value) self.pyoutput(feature)
def close(self): """This method is called once all the FME Features have been processed from input(). """ # Do some aggregate processing here... print(self.column1_values)
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.
I did that as well (from another post). But, when I
print('{} has value {}'.format(attr_name, attr_value))
I get this.
Now, I want to access each row as some sort of list. But, attr_value is some kind of FME object. How do I convert it to a list so that I can access each element one by one. I want to do something like
coulumnData = feature.getAttribute('Column1') for row in coulumnData: print(row)
I get this error:
The PythonCaller is called once for each row in your Excel, meaning you cannot access all rows by the column name. You'll have to add them up yourself, e.g.
import fme import fmeobjects
class FeatureProcessor(object):
def __init__(self): """Base constructor for class members.""" self.column1_values = list()
def input(self, feature): """This method is called for each FME Feature entering the PythonCaller. If knowledge of all input Features is not required for processing, then the processed Feature can be emitted from this method through self.pyoutput(). Otherwise, the input FME Feature should be cached to a list class member and processed in process_group() when 'Group by' attributes(s) are specified, or the close() method.
:param fmeobjects.FMEFeature feature: FME Feature entering the transformer. """ value = feature.getAttribute('column1') if value is not None: self.column1_values.append(value) self.pyoutput(feature)
def close(self): """This method is called once all the FME Features have been processed from input(). """ # Do some aggregate processing here... print(self.column1_values)