match function find file in filename . one sign replace nuber

33 views Asked by At

I need to create a pattern that will check and whether the data in the database match the search in the examples I have a search for * txt files. files = "*" meaning each file and example search in which I have a "?" and it will replace every other character in the file: for txt i * I created this way:

 if pattern=='*':
        return True    
if filename.find(pattern): #pattern==*.txt
        return True

now I have to call log12.txt i log1.txt i form of inquiry : log??.txt i log?.txt

('log12.txt', 'log??.txt') #==True

my try is good only if ?==1, error is is in '??" or number is other 1

 for i in filename:
        if filename[i]==pattern[i]:
            odp=True
        if pattern[i]=='?':    #czy w tym miejscu szukanego pliku jest znak
             if filename[i].isdigit():
                continue#czy w tym samym indeksie pliku jest cyfra
        else:
            odp=False
            break
        odp=True
                    #czy znaki w stringu są takie same
    else:
        odp=False
    return odp
print("Example:")
print(unix_match("log1.txt","log?.txt"))#ok
print(unix_match("log55.txt","log??.txt"))#error
print(unix_match("log2.txt","log?.txt"))#error
0

There are 0 answers