Skip to main content

Hi there,

 

I have calculated an attribute by using the Python script in Python caller. I tried to add the attribute in the output using following code at the close function:

for i in self.df22'Normalized_SAIDI_DPP2']:

newFeature = fmeobjects.FMEFeature()

newFeature.setAttribute('Normalized_SAIDI_DPP2',i)

self.pyoutput(newFeature)

The above code add the attribute in the output but the added attribute is not in-lined with the other attributes of the output. For instance, if the current output has 3 columns, and 100 rows of record, after adding new attribute, it would become 4 column, however, the value of 4th column after 100 rows of record, in the first 100 rows value of new column is missing. Could anyone guide about how to inline the value of new added column with the existing value?

Are you, by any chance, splitting off the features to the PythonCaller? That would mean you'd end up with the original set of features and the ones processed by the PythonCaller, so basically a double set.

If you can post a screenshot of your workspace we can hopefully help you better.


I think this is because you are creating create features in the close section of the python script.

 

In the main section which is process each line you will see

self.pyoutput(Feature)

That is outputing that line (the 100 rows without the 4th column)

 

then you are running this in the close section:

for i in self.df2Â'Normalized_SAIDI_DPP2']:
    newFeature = fmeobjects.FMEFeature()
    newFeature.setAttribute('Normalized_SAIDI_DPP2',i)
    self.pyoutput(newFeature)

and that is creating the next 100 lines with just column 4

Therefore you will need to pass the columns or features into self so you get the needed columns into the close section. I hope you have got a unique column!

I have not tried to save a dict of features into the self store but I have for a dict of column values as a list.


I am not 100% clear on what you mean, but I think - instead of creating new features - that you want to add an attribute to the existing features. It would be clearer if you share the full python code of the transformer - but I suspect that you have stored all the input features in a list, then you would loop over the list, add the attrbitute and output.


Are you, by any chance, splitting off the features to the PythonCaller? That would mean you'd end up with the original set of features and the ones processed by the PythonCaller, so basically a double set.

If you can post a screenshot of your workspace we can hopefully help you better.

Hi redgeographics,

Here is the screenshots of the output and the Python script running on the Python caller. The newly added attribute name is Normalized_SAIDI_DPP2.

Output screen shot:

Code


I think this is because you are creating create features in the close section of the python script.

 

In the main section which is process each line you will see

self.pyoutput(Feature)

That is outputing that line (the 100 rows without the 4th column)

 

then you are running this in the close section:

for i in self.df2Â'Normalized_SAIDI_DPP2']:
    newFeature = fmeobjects.FMEFeature()
    newFeature.setAttribute('Normalized_SAIDI_DPP2',i)
    self.pyoutput(newFeature)

and that is creating the next 100 lines with just column 4

Therefore you will need to pass the columns or features into self so you get the needed columns into the close section. I hope you have got a unique column!

I have not tried to save a dict of features into the self store but I have for a dict of column values as a list.

You are right. I am doing it exactly the same way as you mentioned. I am not sure about what do you mean by "pass the column or features into self so you et the needed columns into the close section". Could you please elaborate it by some example?


I am not 100% clear on what you mean, but I think - instead of creating new features - that you want to add an attribute to the existing features. It would be clearer if you share the full python code of the transformer - but I suspect that you have stored all the input features in a list, then you would loop over the list, add the attrbitute and output.

Here is the screen shot of the code:


I think this is because you are creating create features in the close section of the python script.

 

In the main section which is process each line you will see

self.pyoutput(Feature)

That is outputing that line (the 100 rows without the 4th column)

 

then you are running this in the close section:

for i in self.df2Â'Normalized_SAIDI_DPP2']:
    newFeature = fmeobjects.FMEFeature()
    newFeature.setAttribute('Normalized_SAIDI_DPP2',i)
    self.pyoutput(newFeature)

and that is creating the next 100 lines with just column 4

Therefore you will need to pass the columns or features into self so you get the needed columns into the close section. I hope you have got a unique column!

I have not tried to save a dict of features into the self store but I have for a dict of column values as a list.

I have make some changes in the code. Now one problem is gone, newly added attribute is in-lined with the existing output attributes. However, the problem is each cell of newly added attribute contains all new value instead of containing only one value. Here is snapshot of the updated code:

0684Q00000ArMUlQAN.png

Here is the snapshot of newly added attribute column in which each cell contains all values of attribute instead of having one value only. 

0684Q00000ArMP3QAN.png

Could you please guide me, how to fix the issue?


Reply