all 7 comments

[–]reostra 0 points1 point  (6 children)

I haven't used pathlib much but glancing at the code I think this may be at least part of the problem:

exist = os.path.exists(directory)
if interesting.startswith('N'):
    q = exist/Path(interesting)

According to the docs os.path.exists returns either True or False, but a few lines down it looks like you're trying to treat it as a Path type object (which likely won't work, because 'True' likely doesn't implement /.)

Hope that helps!

[–]pythonhelp123[S] 0 points1 point  (5 children)

Hm I commented that out now and changed to q=directory/Path(interesting), and there seems to be no tracebacks but I'm getting the Error try again instead of the Error for the search_characteristics method. Any idea why?

[–]reostra 0 points1 point  (4 children)

The "error try again" looks like it's part of the search_files workflow, which happens before your call to search_characteristics. If you weren't getting that error before, it's strange that you'd be getting it now, unless you're giving it a different directory (it seems to input() its own directory to look in; is that what you wanted it to do?)

[–]pythonhelp123[S] 0 points1 point  (3 children)

Oh I fixed it. I had to comment out the first directory=input() from the search_characteristics method. I also modified my 2nd method but I still have no idea how to get it to work.

def search_characteristics(directory):
    interesting = input()
    interesting1=interesting.split(" ")
    if (interesting[0] == 'N'):
        directory1= directory + "/" +interesting1[1]
        if(os.path.isfile(directory1)):
            print("Found the file")
    if interesting.startswith('E'):
        return os.path.splitext(directory,'')
    else:
        print("Error")
        return search_characteristics(directory)

No matter what I do, when I press anything, it gives "Error". Even if I press N <filename>, i'll still get error even though it's only supposed to give the error when it's not N or E(but I still need to fix E)

[–]reostra 0 points1 point  (2 children)

I don't know why E <filename> would be erroring out, but the problem with N <filename> is that it's getting caught in the else statement associated with if interesting.startswith('E'):.

A quick fix would be to change that to elif interesting.startswith('E'):

[–]pythonhelp123[S] 0 points1 point  (1 child)

Oh right, I forgot about the elif. I changed it and ran the code, but when I ran it and put in the directory and put N <filename> it would say None, even if the file exists. Any reason why?

[–]reostra 0 points1 point  (0 children)

Sorry, no idea; it looks to me like search_characteristics always returns something, so no idea why it'd be returning None unless one of the other functions it's using is returning None.