-5

I am using Python 2.7 in combination with Simulia Abaqus (6.14). I have defined a list of 3-D coordinates in the following format:

selection_points = [(( 1, 2, 3), ), (( 4, 5, 6), ), ((7, 8, 9), )]

I need to use ALL coordinates in selection_points as input for my model. I need each coordinate point individually, so not all of them as a list. For example for an Abaqus function (Abaqus_function) taking three coordinates as input, I could do the following:

Abaqus_function(selection_points[0], selection_points[1], selection_points[2])

Effectively that would look like:

Abaqus_function(((1, 2, 3), ), ((4, 5, 6), ), ((7, 8, 9), ))

Now what if selection_points contains 20 or 100 coordinate points. How could I call every one of them without writing:

Abaqus_function(selection_points[0], selection_points[1], selection_points[2], 
                selection_points[3], ... selection_points[99])

Selection_points[1 : -1] is not the way to go, I do not want another list. Therefore also str(selection_points)[1: -1] is not an option.

Mathijs
  • 1
  • 4

1 Answers1

0

What you are trying to do is to unpack the elements of the list into parameters. This can be done like this:

Albaqus_Function(*coord_list[0:n])

Where n is the last index+1.

The *args notation is used as the following:

arguments = ["arg1", "arg1", "arg3"]
print(*arguments)

This will be equivalent to:

print("arg1", "arg2", "arg3")

This is useful when you don't exactly know how many arguments you need.

Amit Gold
  • 727
  • 7
  • 22
  • I do not quite understand how this works. would you please show how this is handled? for example, use a dummy function showing print. Thanks. – sabbahillel Feb 21 '16 at 17:15
  • @ Amit Gold, Many thanks, that is exactly what I meant. I was not familiar with the *args notation. Now is there a way to make an exception for a specific item? Say I want item 0 to 10 but not the 4th item? – Mathijs Feb 21 '16 at 17:31
  • You just change the list accordingly before you send it with the notation. In what I did, I just changed it in the same line, because `[0:n]` creates another list and sends that list. In your example, you can do `*(args[0:4]+args[5:11])`, but that is unreadable. – Amit Gold Feb 21 '16 at 17:35