-1
Good morning everyone, I’m starting my studies in python and during the programming of a function that goes in the spreadsheet and transfers the values to a dictionary I came up with a question: All functions need a return?
In my case the dictionary was started in the function init so I’ll want the result after the dictionary is filled with all materials from each sector.
I’ll leave the example of the code in case I haven’t been able to be clear.
class ProdutoPai(object):
def __init__(self, quantidade):
self.quantidade = quantidade
self.materiais = {}
self.chaves = ["Codigo", "Descrição", "Quantidade", "Unidade", "Preço"]
def setor(self): """
Essa função acrescenta a self.materiais os materiais usado no DAC para fabricação do modulo base
:return: None
"""
wb = load_workbook(self.url)
ws = wb["setor"]
linhas = ws.max_row
prod = self.materiais["produto 1"] = {}
for linha in range(1, linhas + 1):
prod[ws["A{}".format(linha)].value] = {self.chaves[0]: ws["A{}".format(linha)].value,
self.chaves[1]: ws["B{}".format(linha)].value,
self.chaves[2]: (ws["D{}".format(linha)].value * self.quantidade),
self.chaves[3]: ws["C{}".format(linha)].value,
self.chaves[4]: (ws["F{}".format(linha)].value *
(ws["D{}".format(linha)].value * self.quantidade))}
It is not necessary, it depends on what you need. Whoever calls the function will need the result of it?
– hkotsubo
In this case not only do I need you to change the value of self.materials, the idea would be to return at the end of the whole change process.
– Kelvin Loretto