You may want to take a look at the documentation for feature.getAttribute():
https://docs.safe.com/fme/html/fmepython/api/fmeobjects/_feature/fmeobjects.FMEFeature.getAttribute.html#fmeobjects.FMEFeature.getAttribute
To iterate over all the attributes in a Python block, do something like:
for attr_name in feature.getAllAttributeNames():
attr_value = feature.getAttribute(attr_name)
print('{} has value {}'.format(attr_name, attr_value))
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
attr_value[0] = 'Apple'
attr_value[1] = 'Orange'
attr_value[2] = 'Banana'
But, right I only have this:
print(attr_value)
Apple
Orange
Banana
I want to access each element of attr_value. How do I do that?
When I try to do this:
coulumnData = feature.getAttribute('Column1')
for row in coulumnData:
print(row)
I get this error:

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)
"PythonCaller is called once for each row in your Excel".. now that statement answers all my confusion !! Thanks !
Final question @david_r. How do I expose the values outside of python?
"PythonCaller is called once for each row in your Excel".. now that statement answers all my confusion !! Thanks !
Final question @david_r. How do I expose the values outside of python?
You can either expose them in the lower part of the PythonCaller dialog, or using an AttributeExposer.
