I currently define the tables and columns of a PostgreSQL database like this:
from sqlalchemy.orm import declarative_base
from sqlalchemy import Column, Float, Integer
Base = declarative_base()
class MyTable(Base):
__tablename__ = "my_table"
col_1 = Column(Integer, primary_key=True)
col_2 = Column(Float)
col_3 = Column(Float)
col_4 = Column(Float)
col_5 = Column(Float)
# ....
col_24 = Column(Float)
col_25 = Column(Float)
Instead of writing the same identical lines multiple times, I would like to use a for loop that sets similar columns:
from sqlalchemy.orm import declarative_base
from sqlalchemy import Column, Float, Integer
Base = declarative_base()
class MyTable(Base):
__tablename__ = "my_table"
col_1 = Column(Integer, primary_key=True)
for ind in range(2, 26):
# set col_$ind
????
What should I do put inside the for loop to set the attributes col_$ind
?