How do you use dot notations for Lists in the Python Node?

Simple question, I can use the List.GetItemAtIndex () for example, in the Dynamo Code block. But the same language can’t be used in the Python node. Do I need to import something for the List. operations to appear?

Generally speaking you’re better off using the Python native tools for list manipulation when you are in the Python environment - I certainly would leverage them over the Dynamo version when possible.

But since you asked, you need to first add the DSCoreNodes to the CLR, then import DSCore into the Iron Python Environment before you can call it. Once that is done you can call DSCore.List functions as desired. Autocomplete may not work well with them either as there is a lot of name collision. Also they will almost certainly be slower than the native Python tools, and will not be able to make use of list levels and lacing as you can in Design Script (those are not features of the list function, but features of Design Script).

An example:

1 Like

Thanks for the reply.
A quick follow up question, can you give me a simple example of what do you mean by “Python Native tools” for List manipulation?

@harry_zhao you just need to index your list:

myList[0] is the same as GetItemAtIndex(myList, 0)

Indexing using square brackets is what @jacob.small means by ‘native tools’ i think, plus this is a convention used by most (all?) programming languages for accessing items from lists, so its better in that sense as you will have transferrable skills if you end up using other languages such as C#. Hence, importing an entire library to call Dynamo-specific methods for list manipulation is not a good idea.

2 Likes

Simplest would be list indexing - that is

baseList = IN[0]
index1 = baseList[1]

There is more info I’m the base methods used by the current Dynamo implementation of Python here: 5. Data Structures — Python 2.7.18 documentation

1 Like