Sridhar
Sridhar

Reputation: 61

Python: issue while trying to print a string

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

Upvotes: 0

Views: 64

Answers (1)

Israel Unterman
Israel Unterman

Reputation: 13520

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

Upvotes: 5

Related Questions