Nypt008
Nypt008

Reputation: 103

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

Upvotes: 0

Views: 53

Answers (2)

sahith kumar
sahith kumar

Reputation: 11

First : Check your import statement. Is it function or functions.IT should be the name of your python file name.

Second : your function sort_requests has a return statement. U need to store the returned output.Try this

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

Upvotes: 0

JustForFun
JustForFun

Reputation: 72

add from functions import sort_requests or replace sort_requests(requests) by functions.sort_requests(requests)

Upvotes: 1

Related Questions