Найти - Пользователи
Полная версия: else: return
Начало » Python для новичков » else: return
1
LightOfMooN
так работает:
    def getSectionList(self, obj, list=[]):
loclist=[]
for i in obj.values():
if ISection.providedBy(i):
loclist.append(i)
if loclist != []:
list.append(loclist)
if ISection.providedBy(obj):
self.getSectionList(obj.__parent__,list)
return list
а так всегда возвращает пустую строку
    def getSectionList(self, obj, list=[]):
loclist=[]
for i in obj.values():
if ISection.providedBy(i):
loclist.append(i)
if loclist != []:
list.append(loclist)
if ISection.providedBy(obj):
self.getSectionList(obj.__parent__,list)
else: return list
Почему?
ведь если условие не выполнилось, толжен вернуть list
Ferroman
Эта функция в принципе не может вернуть строку. А если условие выполняется (что, с Ваших слов, и происходит), то, очевидно, она ничего и не возвращает.

PS. Называть переменную как встроенный тип - моветон
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