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
moostang88 wrote:
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
classFeatureProcessor(object):def__init__(self):"""Base constructor for class members."""
self.column1_values = list()
definput(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 isnotNone:
self.column1_values.append(value)
self.pyoutput(feature)
defclose(self):"""This method is called once all the FME Features have been processed
from input().
"""# Do some aggregate processing here...
print(self.column1_values)
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
classFeatureProcessor(object):def__init__(self):"""Base constructor for class members."""
self.column1_values = list()
definput(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 isnotNone:
self.column1_values.append(value)
self.pyoutput(feature)
defclose(self):"""This method is called once all the FME Features have been processed
from input().
"""# Do some aggregate processing here...
print(self.column1_values)
We use 3 different kinds of cookies. You can choose which cookies you want to accept. We need basic cookies to make this site work, therefore these are the minimum you can select. Learn more about our cookies.