from opreation_product import ProductOperation from operation_customer import CustomerOperation from operation_order import OrderOperation po = ProductOperation() co = CustomerOperation() oo = OrderOperation() class IOInterface: def show_list(self,user_role, list_type, object_list): while 1: user_inputs = self.get_user_input('please enter your the list type ' 'and page number that you want to view:') list_type = user_inputs[0] if not list_type.isalpha() and not user_inputs[1].isdigit(): print('invalid input') continue elif user_role == 'customer' and list_type == 'Customer': print('you are only allowed to view Products information and Orders information') continue else: if list_type == 'Customer': object_list = co.get_customer_list(user_inputs[1])[0] row_numbers = len(object_list) total_pages = co.get_customer_list(user_inputs[1])[2] print(object_list,row_numbers,total_pages) break elif list_type == 'Product': object_list = po.get_product_list(user_inputs[1])[0] row_numbers = len(object_list) total_pages = po.get_customer_list(user_inputs[1])[2] print(object_list, row_numbers, total_pages) break elif list_type == 'Order': object_list = oo.get_order_list(user_inputs[1])[0] row_numbers = len(object_list) total_pages = oo.get_order_list(user_inputs)[2] print(object_list, row_numbers, total_pages) break else: print('invalid input, Try again') continue 为什么这个方法中的参数list_type和object_list没有用到 该怎么改?
时间: 2024-02-14 11:10:57 浏览: 63
在该方法中,list_type和object_list参数在函数签名中被定义,但在函数体中没有被使用。如果想使用这两个参数,可以在函数中将它们传递给其他方法或函数进行处理。例如,可以将object_list传递给另一个方法,该方法可以处理对象列表并将其打印出来。而list_type参数可以用来判断用户想要查看的列表类型,从而选择正确的操作对象。以下是修改后的代码示例:
```python
from opreation_product import ProductOperation
from operation_customer import CustomerOperation
from operation_order import OrderOperation
po = ProductOperation()
co = CustomerOperation()
oo = OrderOperation()
class IOInterface:
def show_list(self, user_role, list_type, object_list):
while 1:
user_inputs = self.get_user_input('please enter the list type and page number that you want to view:')
list_type = user_inputs[0]
if not list_type.isalpha() and not user_inputs[1].isdigit():
print('invalid input')
continue
elif user_role == 'customer' and list_type == 'Customer':
print('you are only allowed to view Products information and Orders information')
continue
else:
if list_type == 'Customer':
object_list = co.get_customer_list(user_inputs[1])[0]
row_numbers = len(object_list)
total_pages = co.get_customer_list(user_inputs[1])[2]
self.print_object_list(object_list, row_numbers, total_pages)
break
elif list_type == 'Product':
object_list = po.get_product_list(user_inputs[1])[0]
row_numbers = len(object_list)
total_pages = po.get_customer_list(user_inputs[1])[2]
self.print_object_list(object_list, row_numbers, total_pages)
break
elif list_type == 'Order':
object_list = oo.get_order_list(user_inputs[1])[0]
row_numbers = len(object_list)
total_pages = oo.get_order_list(user_inputs)[2]
self.print_object_list(object_list, row_numbers, total_pages)
break
else:
print('invalid input, Try again')
continue
def print_object_list(self, object_list, row_numbers, total_pages):
print(object_list, row_numbers, total_pages)
```
在上面的代码中,我添加了一个名为print_object_list的新方法,该方法接受object_list、row_numbers和total_pages三个参数,并将它们打印出来。在show_list方法中,当我们从操作对象中获取了对象列表时,我们将这个列表和一些其他信息传递给print_object_list方法,让它负责打印出这些信息。这样,我们就成功地使用了原本未使用的list_type和object_list参数。
阅读全文