reference of a var inside the for global

Asked

Viewed 46 times

0

then, I wanted to know by referencing the date variables, list"

    @app.route("/download", methods=['GET', 'POST'])
    def orac_detal():
                    global orac_detal                
                    state = {'gera':0, 'gera_total_csv':0, 'gera_orcamento':0, 'gera_total':0, 'taxas':0, 'gera_agrupamento':0, 'orac_detal':1}
                    m = np.zeros((156,96))



                    for loja in lojas:
                      if os.path.isfile("./.pickles/orcamentoAux_"+str(loja)+".pickle"):
                        with open(r"./.pickles/orcamentoAux_"+str(loja)+".pickle", "rb") as input_file:
                            foo = pickle.load(input_file)
                            datas = foo['datas'] # lista com todas as datas, para ser o cabeçalho da planilha
                            listaComTudo = foo['listaComTudo'] # lista de lista, em que cada lista interna tem os dados de uma despesa
                            nomesDespesas = foo['nomesDespesas'] # lista com o nome de todas as despesas, para ser inserida no final usando a função de colocar na primeira coluna
                datas=datas, listaComTudo=listaComTudo, nomesDespesas=nomesDespesas

                   for i in range(len(listaComTudo)):
                      m[i] += listaComTudo[i]

                   for i in range(len(listaComTudo)):
                      nomesDespesas[i] = nomesDespesas[i].replace(","," ")
                      listaComTudo[i] = [nomesDespesas[i]] + listaComTudo[i]

                   dicionario = {}
                   for i in range(len(nomesDespesas)):
                      chave = nomesDespesas[i][23:]
                      dicionario[chave] = m[i]  

                  df = pd.DataFrame.from_dict(data=dicionario, orient='index', columns=datas)
                  df.to_csv('despesas_detal.csv ' )

def download_file_named_in_unicode():
    return excel.make_response_from_array('despesas_detal.csv', "xls",
                                          file_name=u"despesas_detal")
  • You’ve used it before global orac_detal to do this, what was the difficulty? Indeed, not even this made sense, since orac_detal is the name of the function.

  • 2

    It would be nice for you to fix the code indentation in the post. In Python this is not a "detail", in which how to get indented was - and the code above gets syntax error on account of indentation.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.