Python join (NameError: name 'join' is not defined)

Question:

Hello there is a function in my companies code that I don’t understand. It does uses join without a preceding string object. Whenever I try to mimick this behaviour in my python shell I get the error:

 (NameError: name 'join' is not defined)

Which makes sense since join is not supposed to work that way

Here is the code:

from datetime import time
import math

def doit(reservations, operationFrom, operationTo):
    ret = [(operationFrom, operationTo, 0)]
    for res in reservations:
        ret = join(res, ret, sum)
    return ret

How come the join doesn’t throw an error? Isn’t join supposed to be used like so for example:

"fkasndfk".join(['x','y','z'])
Asked By: james

||

Answers:

Either your company’s code has a bug and the join call will produce an exception if it’s ever executed (reservations could be empty!), or join is defined somewhere else in the code.

Answered By: John Gordon
from os.path import join

try importing this library. it worked for me

Answered By: Pai
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.