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'])
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.
from os.path import join
try importing this library. it worked for me
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'])
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.
from os.path import join
try importing this library. it worked for me