79139048

Date: 2024-10-29 21:36:37
Score: 1.5
Natty:
Report link

As mentioned, the two calls to the Data class constructor are identical and the scope is equivalent, so it's worth looking at the parameters used in both calls.

You get a TypeError: too many initializers error, which seems to indicate that something is wrong when initializing the Data structure

ctypes structures can be initialized by passing values for the attributes to the constructor, which is what you are doing in your example

I have tried to reproduce vaguely your scenario and got this in the interactive interpreter:

>>> n = 5
>>> x = c_double(3.45); ina = pointer(x)
>>> y = c_double(9.23); outa = pointer(y)
>>> data = Data(n, ina, outa)
>>> data.n; data.ina.contents; data.outa.contents
5
c_double(3.45)
c_double(9.23)

which is good. If I add a parameter for which there is no attribute in the structure, I get the infamous TypeError: too many initializers

>>> data = Data(n, ina, outa, 90)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: too many initializers

Notably, I do not get the same error for type/argument mismatch, so I think this can be a good start. Why more than three arguments are fed to the Data constructor

Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • Me too answer (2.5): get the same error
  • Low reputation (0.5):
Posted by: igmartin