0
import os
from os import path
import datetime
from datetime import date, time, timedelta
import time


def main():
    # Print the name of the OS
    print(os.name)

    # Check for item existence and type
    print("Item exists: " + (str(path.exists("textfile.txt"))))
    #print("Item is a file: " + str(path.isfile("textfile.txt")))
    #print("Item is a directory: " + str(path.isdir("textfile.txt")))

if __name__ == "__main__":
    main()

ERROR:

print ("Item exists: " + (str(path.exists("textfile.txt"))))
TypeError: 'str' object is not callable

0

1 Answer 1

5

According to the error you got, somewhere in your code (which doesn't appear in your post) you assigned to str...

ADDED after reading comments:

This code runs fine. Maybe you run it from an IDE like spyder, where it remembers vars you assigned earlier in the shell or in the code that was executed. Please try to run it from the Windows "DOS" shell and see it the error occurs again. If it doesn't occur, you may restart you IDE and find it's gone there too

Sign up to request clarification or add additional context in comments.

3 Comments

this is my whole code (still getting error): import os from os import path import datetime from datetime import date, time, timedelta import time def main(): # Print the name of the OS print (os.name) # Check for item existence and type print ("Item exists: " + str(path.exists("textfile.txt"))) #print ("Item is a file: " + str(path.isfile("textfile.txt"))) #print ("Item is a directory: " + str(path.isdir("textfile.txt"))) if name == "main": main()
Comments are not a place for code. Please edit your original post with your complete code.
@Israel Yes, I was using IDE spyder. It worked fine when i execute the code after the restart. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.