I have a TypeError in Python
Question:
from Abstractions.Products import Products
from itertools import product
from Implementation.ProductsImplementation import ProductsImplementation
from Implementation.VendorImplementation import VendorImplementation
from Models.VendorSessionModel import VendorSessionModel
if __name__ == '__main__':
vendor = VendorImplementation()
username = input("Enter vendor name:")
password = input("Enter your password:")
login_res = vendor.login(username, password)
if login_res == False:
print("Not authorized Vendor")
else:
products = ProductsImplementation(username)
print("Enter Number of product you want to add:")
p = Products()
n= int(input())
for i in range(1, n+1):
product_name = input("Please Enter Product Name:")
product_type = input("Please Enter product type:")
available_quantity = input("Please enter avilable quantity:")
unit_price = input("please enter unit price:")
p.add_product()
Products Class code
class Products:
def add_product(self, product_name, product_type, available_quantity, unit_price):
"""This abstract method will be used to add products"""
pass
ProductsImplementation class code
class ProductsImplementation(Products):
def __init__(self, username):
self.product_model = ProductModel()
self.vendor_session = VendorSessionModel()
self._username = username
def add_product(self, product_name, product_type, available_quantity, unit_price):
if not self.vendor_session.check_login(self._username):
print("please login first")
return False
self.product_model.add_product(product_name,product_type,available_quantity,unit_price)
print(product_name + "added sucessfully")
Below is the error I get when I try to run this
Traceback (most recent call last):
File "e:psython_projectM01-W01-02-Ecommerce_vendor_managementDriver.py", line 28, in <module>
p.add_product()
TypeError: Products.add_product() missing 4 required positional arguments: 'product_name', 'product_type', 'available_quantity', and 'unit_price'**
Answers:
You forgot to provide the arguments to the add_product
method. Change the last line to:
p.add_product(product_name, product_type, available_quantity, unit_price)
from Abstractions.Products import Products
from itertools import product
from Implementation.ProductsImplementation import ProductsImplementation
from Implementation.VendorImplementation import VendorImplementation
from Models.VendorSessionModel import VendorSessionModel
if __name__ == '__main__':
vendor = VendorImplementation()
username = input("Enter vendor name:")
password = input("Enter your password:")
login_res = vendor.login(username, password)
if login_res == False:
print("Not authorized Vendor")
else:
products = ProductsImplementation(username)
print("Enter Number of product you want to add:")
p = Products()
n= int(input())
for i in range(1, n+1):
product_name = input("Please Enter Product Name:")
product_type = input("Please Enter product type:")
available_quantity = input("Please enter avilable quantity:")
unit_price = input("please enter unit price:")
p.add_product()
Products Class code
class Products:
def add_product(self, product_name, product_type, available_quantity, unit_price):
"""This abstract method will be used to add products"""
pass
ProductsImplementation class code
class ProductsImplementation(Products):
def __init__(self, username):
self.product_model = ProductModel()
self.vendor_session = VendorSessionModel()
self._username = username
def add_product(self, product_name, product_type, available_quantity, unit_price):
if not self.vendor_session.check_login(self._username):
print("please login first")
return False
self.product_model.add_product(product_name,product_type,available_quantity,unit_price)
print(product_name + "added sucessfully")
Below is the error I get when I try to run this
Traceback (most recent call last):
File "e:psython_projectM01-W01-02-Ecommerce_vendor_managementDriver.py", line 28, in <module>
p.add_product()
TypeError: Products.add_product() missing 4 required positional arguments: 'product_name', 'product_type', 'available_quantity', and 'unit_price'**
You forgot to provide the arguments to the add_product
method. Change the last line to:
p.add_product(product_name, product_type, available_quantity, unit_price)