我有以下代码,这会导致 Python“意外退出”:
def profile_videos_sort_and_filter(profile, sort, filter, uncredited_videos, list_of_credits=[]):
"""Given a sort and filter, this will order the credits and return a credit_set."""
if filter == 'user' or filter == 'all':
if filter == 'user':
credit_set = profile.videocredit_set.filter(video__uploaded_by=profile)
if filter == 'all':
credit_set = profile.videocredit_set.all()
if sort == 'alphabetical':
credit_set = conform_videos_and_credits(credit_set, uncredited_videos, sort)
if sort == 'newest':
credit_set = conform_videos_and_credits(credit_set, uncredited_videos, sort)
if sort =='position':
credit_set = credit_set.order_by('position')
list_of_credits = position_credit_set(profile, credit_set, filter, uncredited_videos)
elif filter == 'others':
credit_set = profile.videocredit_set.exclude(video__uploaded_by=profile)
if sort == 'alphabetical':
credit_set = credit_set.order_by('video__title')
if sort == 'newest':
credit_set = credit_set.order_by('video__uploaded_at')
if sort == 'position':
credit_set = credit_set.order_by('position')
list_of_credits = position_credit_set(profile, credit_set, filter, uncredited_videos)
#### THIS IS THE PART THAT CAUSES THE ERROR ###
else:
### if none of the above, call the function, passing default parameters ###
profile_videos_sort_and_filter(profile, uncredited_videos=uncredited_videos,
sort='position', filter='newest')
return credit_set, list_of_credits
如何将最后的 else 子句更改为有效?谢谢。
最佳答案
为 sort='position'
和/或 filter='newest'
添加条件。
关于python - 摆脱Python中的递归循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7061018/