関数を書くためのよりクリーンな方法を探してい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'])