import os, fnmatch dirpath = input('Путь к каталогу: ') while not os.path.isdir(dirpath): #проверка пути print('Такого каталога нет') dirpath = input('Путь к каталогу: ') filename = input('Имя файла: ') path_f = [] for d,dirs,files in os.walk(dirpath): for f in files: if fnmatch(f, filename): path = (os.path.join(d, f)) path_f.append(path) 

The program issues:

 if fnmatch(f, filename): 

TypeError: 'module' object is not callable

  • If you are given the right answer, it is customary to mark it with the right one, so that the rest will be immediately clear that the problem has been solved and no additional clarifications / answers are needed. - Vadim Shender

1 answer 1

You are importing the fnmatch module and trying to use it as a function.

You need to either import the fnmatch function from the fnmatch module like so:

 import os from fnmatch import fnmatch 

Or, leaving such an import as you have, use the full name of the function:

 ... if fnmatch.fnmatch(f, filename): ...