You want to create a class which contains name and place fields.

class Baz():
    "Stores name and place pairs"
    def __init__(self, name, place):
        self.name = name
        self.place = place

Then you'd use a list of instances of that class.

my_foos = []
my_foos.append(Baz("foo", "Shop"))
my_foos.append(Baz("bar", "Home"))

See also: classes (from the Python tutorial).

Answer from Matt Ball on Stack Overflow
🌐
Python
docs.python.org › 3 › library › struct.html
struct — Interpret bytes as packed binary data
Several struct functions (and methods of Struct) take a buffer argument. This refers to objects that implement the Buffer Protocol and provide either a readable or read-writable buffer. The most common types used for that purpose are bytes and bytearray, but many other types that can be viewed as an array of bytes implement the buffer protocol, so that they can be read/filled without additional copying from a bytes object.
🌐
NumPy
numpy.org › doc › stable › user › basics.rec.html
Structured arrays — NumPy v2.5 Manual
The simplest way to assign values to a structured array is using python tuples. Each assigned value should be a tuple of length equal to the number of fields in the array, and not a list or array as these will trigger numpy’s broadcasting rules.
🌐
Quora
quora.com › How-can-I-implement-a-C-like-struct-create-an-array-of-such-a-struct-and-then-read-such-data-in-Python
How to implement a C like struct, create an array of such a struct and then read such data in Python - Quora
Answer (1 of 4): To create a struct like object you have a few choices: * Tuple - but then you don’t get get field names only index numbers. * Namedtuples - you get field names but each struct is immutable * Dictionary - you have field names by using strings as keys - but you have to remember...
🌐
Python Module of the Week
pymotw.com › 2 › struct
struct – Working with Binary Data - Python Module of the Week
import struct import binascii s = struct.Struct('I 2s f') values = (1, 'ab', 2.7) print 'Original:', values print print 'ctypes string buffer' import ctypes b = ctypes.create_string_buffer(s.size) print 'Before :', binascii.hexlify(b.raw) s.pack_into(b, 0, *values) print 'After :', binascii.hexlify(b.raw) print 'Unpacked:', s.unpack_from(b, 0) print print 'array' import array a = array.array('c', '\0' * s.size) print 'Before :', binascii.hexlify(a) s.pack_into(a, 0, *values) print 'After :', binascii.hexlify(a) print 'Unpacked:', s.unpack_from(a, 0) The size attribute of the Struct tells us ho
🌐
Omz Software
omz-software.com › pythonista › numpy › user › basics.rec.html
Structured arrays (aka “Record arrays”) — NumPy v1.8 Manual
>>> x[1] = (-1,-1.,"Master") >>> x array([(1, 4.0, 'Hello'), (-1, -1.0, 'Master')], dtype=[('f0', '>i4'), ('f1', '>f4'), ('f2', '|S10')]) >>> y array([ 4., -1.], dtype=float32) One defines a structured array through the dtype object. There are several alternative ways to define the fields of a record.
Find elsewhere
🌐
Python Data Science Handbook
jakevdp.github.io › PythonDataScienceHandbook › 02.09-structured-data-numpy.html
Structured Data: NumPy's Structured Arrays | Python Data Science Handbook
But this is a bit clumsy. There's nothing here that tells us that the three arrays are related; it would be more natural if we could use a single structure to store all of this data. NumPy can handle this through structured arrays, which are arrays with compound data types.
🌐
Real Python
realpython.com › python-data-structures
Common Python Data Structures (Guide) – Real Python
August 26, 2020 - A restricted parking lot corresponds to a typed array data structure that allows only elements that have the same data type stored in them. Performance-wise, it’s very fast to look up an element contained in an array given the element’s index. A proper array implementation guarantees a constant O(1) access time for this case. Python includes several array-like data structures in its standard library that each have slightly different characteristics.
🌐
SciPy
docs.scipy.org › doc › numpy-1.15.0 › user › basics.rec.html
Structured arrays — NumPy v1.15 Manual
July 24, 2018 - The simplest way to assign values to a structured array is using python tuples. Each assigned value should be a tuple of length equal to the number of fields in the array, and not a list or array as these will trigger numpy’s broadcasting rules.
Top answer
1 of 1
1

I want to start with the note that I don't see where is the entry_count attribute initialized.

Iterating over a pointer as if it was a sized array is conceptually wrong (as also pointed out in [Python 3]: ctypes - A foreign function library for Python). In C, it's possible to go beyond an array bounds, but ctypes forbids it.
Here's a simpler example that uses ctypes.c_char as the base type (MessageEntry correspondent).

code.py:

#!/usr/bin/env python3

import sys
import ctypes


def main():
    CharArr5 = ctypes.c_char * 5
    b5 = b"12345"
    ca5 = CharArr5(*b5)
    print("Print array ...")
    for c in ca5:
        print(c)

    cp = ctypes.cast(ca5, ctypes.POINTER(ctypes.c_char))
    max_values = 10
    print("\nPrint pointer (max {:d} values) ...".format(max_values))
    for idx, c in enumerate(cp):
        print(c)
        if idx >= max_values:
            print("Max value number reached.")
            break


if __name__ == "__main__":
    print("Python {:s} on {:s}\n".format(sys.version, sys.platform))
    main()

Output:

(py_064_03.06.08_test0) e:\Work\Dev\StackOverflow\q054178876>"e:\Work\Dev\VEnvs\py_064_03.06.08_test0\Scripts\python.exe" code.py
Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] on win32

Print array ...
b'1'
b'2'
b'3'
b'4'
b'5'

Print pointer (max 10 values) ...
b'1'
b'2'
b'3'
b'4'
b'5'
b'\x00'
b'\x00'
b'\x00'
b'\x00'
b'\x00'
b'\x00'
Max value number reached.

As seen, it is possible to iterate over the pointer, but the loop never ends (it will end when reaching an unavailable / invalid memory address, and the program will segfault (Access Violation)).

Assuming that entry_count is properly initialized (if not, make sure to initialize it), use it to keep the loop inside bounds (as shown below):

for idx in range(msg.entry_count):
    msg.entries[idx]  # Do smth with it
    # ...


for idx, entry in enumerate(msg.entries):
    if idx >= msg.entry_count:
        break
    entry  # Do smth with it
    # ...

Or you could use one of the above to implement Iterator Protocol for Message.

🌐
Python Module of the Week
pymotw.com › 3 › struct
struct — Binary Data Structures
December 9, 2018 - import array import binascii import ctypes import struct s = struct.Struct('I 2s f') values = (1, 'ab'.encode('utf-8'), 2.7) print('Original:', values) print() print('ctypes string buffer') b = ctypes.create_string_buffer(s.size) print('Before :', binascii.hexlify(b.raw)) s.pack_into(b, 0, *values) print('After :', binascii.hexlify(b.raw)) print('Unpacked:', s.unpack_from(b, 0)) print() print('array') a = array.array('b', b'\0' * s.size) print('Before :', binascii.hexlify(a)) s.pack_into(a, 0, *values) print('After :', binascii.hexlify(a)) print('Unpacked:', s.unpack_from(a, 0)) The size attri
🌐
GitConnected
levelup.gitconnected.com › fully-explained-array-data-structure-in-python-67dd9a12b695
Fully Explained Array Data Structure in Python | by Amit Chauhan | Level Up Coding
November 13, 2022 - Have you wondered how the Python ... all of this is possible using arrays. An array is nothing but a collection of items stored in adjacent memory locations....
🌐
Python
mail.python.org › pipermail › tutor › 2001-May › 005958.html
[Tutor] Array of structures
May 22, 2001 - What's nice is that Python's lists can grow: we can append() new elements to them: ### >>> names =3D ['glen'] >>> names.append('danny') >>> names ['glen', 'danny'] ### so you don't need to worry so much about sizing Python lists: they'll expand for you. When we're doing structures in Python, we can either bundle the whole thing together as a list: ### def MakeDate(month, day, year): return [month, day, year] def GetMonth(date): return date[0] def GetDay(date): return date[1] def GetYear(date): return date[2] ### or as a dictionary: ### def MakeDate(month, day, year): return { 'month' : month, 'day' : day, 'year' : year } def GetMonth(date): return date['month'] def GetDay(date): return date['day'] def GetYear(date): return date['year'] ### (I'm renaming your struct Day as a "Date" --- I thought that the name was a little confusing.)
🌐
TutorialsPoint
tutorialspoint.com › python_data_structure › python_arrays.htm
Python - Arrays
Unlike other programming languages like C++ or Java, Python does not have built-in support for arrays. However, Python has several data types like lists and tuples (especially lists) that are often used as arrays but, items stored in these types of
🌐
NumPy
numpy.org › doc › 2.1 › user › basics.rec.html
Structured arrays — NumPy v2.1 Manual
The simplest way to assign values to a structured array is using python tuples. Each assigned value should be a tuple of length equal to the number of fields in the array, and not a list or array as these will trigger numpy’s broadcasting rules.