-2

I have to check that file exists or not, and if it does, have to return path to it , the main problem is that os.path.isdir returns only True or False depending on existence, so it seems it does not fit. Any hints? Current schema in my mind is:

def get_config_path():
    if exists(path1):
        return path1
    if exists(path2):
        return path2
d.sci
  • 5
  • 1
  • 4
  • And where do `path1` and `path2` come from? If they are not defined in the function you should use parameters. – Matthias Oct 01 '17 at 20:09

1 Answers1

0

Invoke os.stat(filename) where filename can be a file or directory path. If the file exists, it will return a valid stat object. Otherwise, it throws a FileNotFound exception.

selbie
  • 100,020
  • 15
  • 103
  • 173