0
Good night.
Application developed in Python 3.x Database: sqlalchemy. I’m trying to develop a simple product registration system in an SQL database. For this, I am trying to develop from the MVC Standard (Model, View and Controller). In this sense, I created the classes in the way I thought they were correct (according to the project file). The problem is occurring within the Productoctr class.
'''Products from Database.database import Conexaodb from Database.database import Tables
Class productosdao:
def prod_Cadastrar(produto):
# Conexão
conexaoDB = ConexaoDB()
db = conexaoDB.db()
meta = conexaoDB.meta()
# Tabelas
table = Tabelas()
prodTable = table.prod_Table()
# Inserir no DB
db.excute(prodTable.insert(), [{'prod_Desc': produto.prod_Desc,
'prod_Unid': produto.prod_Unid,
'prod_VrUnit': produto.prod_VrUnit}])
** Controller module **
from Model.DTO.produtosDTO import ProdutosDTO
from Model.DAO.produtosDAO import ProdutosDAO
class ProdutosCTR:
def prod_Cadastrar(self, prod_Desc, prod_Unid, prod_VrUnit):
produtoDTO = ProdutosDTO()
produtoDTO.prod_Desc = prod_Desc
produtoDTO.prod_Unid = prod_Unid
produtoDTO.prod_VrUnit = prod_VrUnit
produtoDAO = ProdutosDAO()
produtoDAO.prod_Cadastrar(produtoDTO)
As it is possible to notice, in this class the prod_Cadastar() function of the product object DAO receives as parameter the product DTO, whose attributes have been filled in the interface:
** Interface **
from Controller.produtosCTR import ProdutosCTR
class Interface:
def prod_Cadastrar(self):
prodCTR = ProdutosCTR()
desc = self.prod_CadDesc()
unid = self.prod_CadUnid()
vr_unit = self.prod_CadVrUnit()
prodCTR.prod_Cadastrar(desc, unid, vr_unit)
def prod_CadDesc(self):
self.descricao = str(input('Descrição: ')).upper()
return self.descricao
def prod_CadUnid(self):
self.unid = str(input('Unidade: ')).upper()
return self.unid
def prod_CadVrUnit(self):
self.valorUnit = float(input('Valor Unitário: '))
return self.valorUnit
When trying to execute the code the following error appears:
"C: Users theu_ Pycharmprojects Melon v. 0.0.1 venv Scripts python.exe" "C:/Users/theu_/Pycharmprojects/Melon v. 0.0.1/main.py" Description: Matheus Unit: kg Unit Value: 10 Traceback (Most recent call last): File "C:/Users/theu_/Pycharmprojects/Melon v. 0.0.1/main.py", line 7, in int.prod_Cadastrar() File "C: Users theu_ Pycharmprojects Melon v. 0.0.1 View interface.py", line 14, in prod_Cadastrar prodCTR.prod_Cadastrar(desc, unid, vr_unit) File "C: Users theu_ Pycharmprojects Melon v. 0.0.1 Controller productsCTR.py", line 18, in prod_Cadastrar produtoDAO.prod_Cadastrar(produtoDTO) Typeerror: prod_Cadastrar() takes 1 positional argument but 2 Were Given
Process finished with Exit code 1
Can someone help me understand the problem? Thank you very much.
By error it is clear that in class
ProdutosDTO
you defined the methodprod_Cadastrar
with a number of arguments, but when you invoke it, you pass another number. Review this.– Woss
I think you meant Productosdao. In this case, I edited the question and added the class quoted. If you could take a look. Thank you.
– Hou17
The argument was missing
self
or define the method as static.– Woss