On Sun, Oct 10, 2021 at 4:23 PM Facundo Batista <facundobati...@gmail.com>
wrote:
>
>     struct.pack_into(format, buffer, offset, v1, v2, ...)

I've encountered this wart with pack and pack_into too.

The current interface makes sense when if v1, v2 are a small number of
items from a data record, but it becomes a bit silly when v1, v2, ... are
the elements of an array of 10 000 integers, for example.

The option to take a list-like argument like you suggest is a good idea,
but maybe this should have its own function or is just outside the scope of
the built-in struct module.

Multiprocessing sort of added support for this via multiprocessing.Array --
see
https://stackoverflow.com/questions/9754034/can-i-create-a-shared-multiarray-or-lists-of-lists-object-in-python-for-multipro.
I haven't looked at what multiprocessing.Array does under the hood.

Summary of the StackOverflow answer for those who don't feel like clicking:

   mp_arr = mp.Array(c.c_double, size)
   # then in each new process create a new numpy array using:
   arr = np.frombuffer(mp_arr.get_obj())

- Simon
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/6S6Q437G3JS5TCKJ2SEKQ5DNRYMDZKIK/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to