Data container with numeric field names

147 views Asked by At

Is there a way in python to create a data container with numeric field names?

A minimal example: I have variables called beta0, beta1, beta2 and would like to pack them into a container beta and access them by beta.0, beta.1, beta.2.

I checked recordclass, namedtuple, and dataclass, but none of them allows this.

EDIT: What is the best practice in python for treating a bunch of related parametres?

1

There are 1 answers

1
Crysers On

you could simply use a dictionary and access them.

beta={0: beta0, 1: beta1, 2: beta2}

Access them with

beta[0]
beta[1]
...

If you need to use the numeric value as variable you can also do this by indexing: eg.

for num in range(3):
    print(beta[num])