我正在寻找一种更简洁的方法来编写lookup_and_url
函数。我认为必须有一种更简洁的方式来声明和实现我的逻辑。我已尽力准确描述代码本身的外部函数和内部函数:
def render(opener='corp'):
"""render will render a carousel of videos, with the opener being
corp or uk and the follower being the other"""
def lookup_and_url():
""""lookup_and_url() returns the DOM id and url for the
opening video (the opener) and the video to follow (the follower).
It returns a dictionary that allows a loop to make a DOM
lookup of the id of the HTML element and then replace its
`src attribute with the provided URL
"""
src = dict(
corp='http://www.youtube.com/embed/0lrqEGlu0Fo',
uk='http://www.youtube.com/embed/30MfCTLhdZ4'
)
if opener == 'corp':
return dict(
opener = dict(lookup='opener', src=src['corp']),
follower = dict(lookup='follower', src=src['uk'])
)
else:
return dict(
opener = dict(lookup='opener', src=src['uk']),
follower = dict(lookup='follower', src=src['corp'])
)
lookup_and_src = lookup_and_url()
for replace in lookup_and_src:
root.findmeld(lookup_and_src['lookup']).attributes(src=lookup_and_src['src'])