Skip to main content
Solved

Setting a list of lists as a _list attribute in PythonCaller?

  • October 30, 2023
  • 2 replies
  • 53 views

fneal
Contributor
Forum|alt.badge.img+4

I have a list of lists resembling this structure:

sublists = [[1,2,3],[4,5,6],[7,8,9]]

 

When I try to set this "list of lists" into a list attribute I get the following:

code -

feature.setAttribute('chunkList{}', sublists)

 

error -

Python Exception <TypeError>: Could not convert attribute value to a supported attribute type.

Traceback (most recent call last):

 File "<string>", line 95, in input

TypeError: Could not convert attribute value to a supported attribute type.

Error encountered while calling method `input'

PythonCaller_Get_chunkList (PythonFactory): PythonFactory failed to process feature

 

  1. The goal is to have a list of 1000 unique IDs or less to feed into a reader
  2. I do not know how many lists there will be ahead of time so I need to dynamically break out the lists into individual lists of 1000 elements later in the workflow which is why I want 1 list of lists to start with.

 

 

 

Best answer by david_r

Try something like

sublists = [[1,2,3],[4,5,6],[7,8,9]]
for n, item in enumerate(sublists):
    feature.setAttribute('chunkList{%s}.sublist{}' % n, item)

Result:

imageYou can then do a ListExploder on chunkList, if you need to have one feature per sublist.

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.

2 replies

david_r
Celebrity
  • Best Answer
  • October 30, 2023

Try something like

sublists = [[1,2,3],[4,5,6],[7,8,9]]
for n, item in enumerate(sublists):
    feature.setAttribute('chunkList{%s}.sublist{}' % n, item)

Result:

imageYou can then do a ListExploder on chunkList, if you need to have one feature per sublist.


fneal
Contributor
Forum|alt.badge.img+4
  • Author
  • Contributor
  • October 30, 2023

Thanks for the quick response @david_r​, that did the trick! I did want each feature to have its own sub-list which I exposed and then concatenated, giving me the queries I will need for each set of records to fetch from a reader.

 

Sublists