Define automatically (loop) all statements in class definition (python)

38 views Asked by At

For storing some tabulated data, my system requires declaring a class. No way around it as it is build this way and I have no control on changing this.

The thing is that my tabulated data have a large number of columns, all of the same type. I should follow the following structure:

class ClassName:
    <statement-1>
    .
    .
    .
    <statement-N>

My question now is, is there a way to define in a loop these statements? Since they are all the same (one for each column, all column type is the same), or I am forced to write manually the statements for each individual column?

Did not try anything because I don't know how to proceed. The only way I would approach the problem is to brute force the class definition (write all individual statements).

class ClassName:
    columnA: type
    .
    .
    .
    columnZZZ: type
0

There are 0 answers