There are many people who need to be manually entered into the code.
Use the format that is most convenient for the person who enters data, for example, a simple text file in csv format:
M, 8 800 555 35 35, 89008007060 F, 8 999 888 77 66, 8 123 456 78 90
or create a small UI for convenience (text or GUI or use an existing interface such as Excel) to check the correctness of the data on the fly (that the field contains only two values (genderqueer does not exist), numbers contain digits, etc.) and write to the database such as sqlite directly (when reading later, you can use row_factory to get the objects of the desired type to get or use the type provided by the ORM such as in sqlalchemy ).
Data about these people will never change
In such cases, it is convenient to use collections.namedtuple , if the object type is specified manually:
Person = namedtuple('Person', 'sex numbers') andrew = Person("Male", ("8 800 555 35 35", "8 900 800 70 60")) julia = Person("Female", ("8 999 888 77 66", "8 123 456 78 90"))
In this case, you cannot change the available attributes, for example, as julia.age = 10 and julia.numbers = () prohibited.
If you want to change existing attributes, add new ones, then to create such objects on the fly (attribute names and data are set dynamically at runtime and can be changed later), you can use types.SimpleNamespace use . Related question: Python: create object and add attributes to it .
What is the difference between the two codes below?
Usually all attributes of an object should be specified in __init__ additional attributes should not be defined outside __init__ without special reason. The second example of the code in question is closer to SimpleNamespace (without some convenient methods), the first example of code in question is closer to namedtuple (without guarantees of immutability).