Skip to content

Instantly share code, notes, and snippets.

@daeken
Created January 10, 2010 02:03
Show Gist options
  • Save daeken/273284 to your computer and use it in GitHub Desktop.
Save daeken/273284 to your computer and use it in GitHub Desktop.
def select(name, cur=None, options=()):
options = ((v, v) if isinstance(v, str) else v for v in options)
return '<select name="%s">%s</select>' % (
name,
''.join('<option%s%s>%s</option>' % (
' selected' if cur == value else '',
(' value="%s"' % value) if value != name else '',
name
) for value, name in options)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment