Найти - Пользователи
Полная версия: Не пойму где ошибка, фукция возращает None, а должна False
Начало » Центр помощи » Не пойму где ошибка, фукция возращает None, а должна False
1
Xryst
Не пойму где ошибка, должно вернуть False…если нет пути, а возращает None
def file_search(folder, filename):
    way_to_file = folder[0]
    for i in folder :
        if i == filename:
            return  way_to_file + '/' + filename
        elif type(i) == list :
            found_file=file_search(i, filename)
            if found_file!=None:
                return way_to_file + '/' + found_file
            if found_fil == None:
                return 'False'
van
Может так?
def file_search(folder, filename):
    n = False
    way_to_file = folder[0] + '/'
    for i in folder:
        if i == filename:
            return way_to_file + i
        elif type(i) == list:
            try:
                way_to_file += file_search(i, filename)
                return way_to_file
            except TypeError:
                continue
    # если файла нет в заданном списке каталогов, то
    if n == False:
        return n
Xryst
Можно вопрос, а как в python вызвать фукцию file_search для ёё проверки?
Нпример вызвать фукцию с такими ргументами
 (['C:', 'backup.log', 'ideas.txt'], 'ideas.txt')
sander
почему бы не использовать os.path ?
Xryst
sander
почему бы не использовать os.path ?
честно, я не пойму как сним работать((
terabayt
Xryst
а как в python вызвать фукцию file_search для ёё проверки?
print file_search(['C:', 'backup.log', 'ideas.txt'], 'ideas.txt')
sander
почему бы не использовать os.path ?
http://python.su/forum/topic/26338/
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB