TypeError: Error: unsupported operand type(s) for +: 'builtin_function_or_method' and 'str'

510 Views Asked by At
    import os

directory = os.getcwd


if os.path.exists(directory + "\\token.txt"):
    print('token file aleady exists. terminating token setup')
else:
    tokenfile =  open("token.txt", "x")

the error is coming from this line: if os.path.exists(directory + "\token.txt"). I am not sure how to fix this error. can anyone help?

1

There are 1 best solutions below

0
On

Python functions must be called with () after the method name.

The correct code you need is:

import os
directory = os.getcwd()
if os.path.exists(directory + "\\token.txt"):
 print('token file aleady exists. terminating token setup')```