简体   繁体   English

此代码有什么问题?

[英]What's the issue with this code?

This is my part of the code: 这是我的代码部分:

import functions
def assign_tasks(operators, requests, current_time):
    sort_requests(requests)
    print(requests)

The error is: 错误是:

NameError: name 'sort_requests' is not defined

The function module has the following functions: 功能模块具有以下功能:

def sort_requests(requests):
   requests.sort(key=operator.itemgetter(3),reverse=True)
   return requests 
def sort_operators_hours(operators):
   operators.sort(key=operator.itemgetter(4))
   return operators

from functions import sort_requests添加from functions import sort_requests或用sort_requests(requests)替换sort_requests(requests) functions.sort_requests(requests)

First : Check your import statement. 首先:检查您的进口声明。 Is it function or functions.IT should be the name of your python file name. 是函数还是函数.IT应该是您的python文件名的名称。

Second : your function sort_requests has a return statement. 第二:您的函数sort_requests具有return语句。 U need to store the returned output.Try this 您需要存储返回的输出。

import functions
def assign_tasks(operators, requests, current_time):
    requests = sort_requests(requests)
    print(requests)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM