SmOg3R
SmOg3R

Reputation: 294

Python `os.path.isfile()` always returns TRUE

import os.path
import sys

try:
    os.path.isfile("random3664746474746.txtxtxtxtx")
    #os.path.isfile(ros.path.join(os.getcwd(), a))
except:
    print("ERROR!")
    exit(3)

I'am confused. No matter what file name I give it, it always returns TRUE! Am I missing something?

Upvotes: 2

Views: 1108

Answers (1)

lapinkoira
lapinkoira

Reputation: 8988

If it returns FALSE it's not an exception

import os.path

if not os.path.isfile("random3664746474746.txtxtxtxtx"):
    print("ERROR!")
    exit(3)

Upvotes: 3

Related Questions