Skip to main content
Solved

python list

  • Oct 27, 2015 10:38 AM UTC
  • 2 replies
  • 91 views

Forum|alt.badge.img+2

Hi

 

Looking at the FME online help for lists, I want to create this type of list in PythonCaller and use it in Workbench as a list:

 
 somelist{0}.length = 7.3 somelist{0}.kind = ’paved’ somelist{1}.length = 8.4 somelist{1}.kind = ’smooth’ somelist{1}.lanes = 2 somelist{2}.length = 1.1 somelist{2}.kind = ’rough’
 

I've created a simple list (element with an index) but struggling using fmeobjects and other libraries in the PythonCaller to create and set this complex list.

 

 

Anyhelp from the Python Jedi out there?  

Thanks

Best answer by takashi

Hi,

 

 

This example help you?

 

-----

 

def processFeature(feature):

 

    # Test data

 

    length, lanes, kind = [7.3, 8,4, 1.1], ['', 2, ''], ['paves', 'smooth', 'rough']

 

    

 

    # Create a structured list attribute.

 

    for i, (lgt, lns, knd) in enumerate(zip(length, lanes, kind)):

 

        feature.setAttribute('somelist{%d}.length' % i, lgt)

 

        feature.setAttribute('somelist{%d}.lanes' % i, lns)

 

        feature.setAttribute('somelist{%d}.kind' % i, knd)

 

-----

 

Padawan Takashi
View original
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

takashi
Celebrity
  • Best Answer
  • Oct 27, 2015 10:55 AM UTC
Hi,

 

 

This example help you?

 

-----

 

def processFeature(feature):

 

    # Test data

 

    length, lanes, kind = [7.3, 8,4, 1.1], ['', 2, ''], ['paves', 'smooth', 'rough']

 

    

 

    # Create a structured list attribute.

 

    for i, (lgt, lns, knd) in enumerate(zip(length, lanes, kind)):

 

        feature.setAttribute('somelist{%d}.length' % i, lgt)

 

        feature.setAttribute('somelist{%d}.lanes' % i, lns)

 

        feature.setAttribute('somelist{%d}.kind' % i, knd)

 

-----

 

Padawan Takashi

Forum|alt.badge.img+2
  • Author
  • Oct 27, 2015 11:21 AM UTC
Think that gives me something to work with. Many Thanks Takashi!