Using CSV file in Django choices

I have this function that calls the choices and activates them in each Model, however, I would like to know if there is a way to use this CSV file automatically, without having to call it item by item...


def Equipe():
    with open("controle_pav/static/texto/equipes.csv", 'r') as arquivo:
        equipes = arquivo.read()
            EQUIPE = (                
                ('equipes', equipes.split()[0]),
                ('equipes', equipes.split()[1]),
                ('equipes', equipes.split()[2]),
                        )
        return EQUIPE

Is there a way to use an iterator or something like that. ?

I tried to make a router with the for but I was not successful

You can use pandas to read the CSV as follows:

import pandas as pd
equipes = pd.read_csv("controle_pav/static/texto/equipes.csv", sep=" ", header=None)

equipes will be a pandas DataFrame, which supports all kinds of manipulation.

Pandas library could be your solution: https://pandas.pydata.org/

Please explain more about your csv file and what your Equipe function should return exactly if you need further help

Back to Top