-3

I recently came across this python code...

array_type = (GL.GLfloat * len(vertexPositions))
final = array_type(*vertexPositions)

but i don't understand what array_type(*vertesPositions) is what it means and what it does... can anyone explain it to me?

Woundrite
  • 1
  • 3
  • perhaps see https://treyhunner.com/2018/10/asterisks-in-python-what-they-are-and-how-to-use-them/ – Mustafa Aydın Apr 12 '21 at 12:57
  • `(GL.GLfloat * len(vertexPositions))(*vertexPositions)` creates and array of floats initializes with the content of the containers `vertexPositions`. – Rabbid76 Apr 12 '21 at 13:00

1 Answers1

0

The * python operator can sometimes be a bit confusing. It obviously can be used to make a simple product between objects that provide the appropriates magic methods, like int, float, str etc. e.g. 2*4 or 'Hi!'*3. But the * operator can also be used to do what's called decomposition, it means it can be used to unpack the values of an iterable. Just to be clear – don't know if it means something to you – it is the python equivalent of javascript's ... operator.

For example, the following will print a-b-c.

x = ['a','b','c']
print(*x, sep='-')

For more about the * operator i'd suggest you to read this

Giuppox
  • 1,393
  • 9
  • 35