Name
getfirst
Synopsis
f
.getfirst(key
,default
=None)
When
f
.has_key(
key
)
,
and
f
[
key
].value
is a single value, not a list of values, getfirst
returns
f
[
key
].value
.
When
f
.has_key(
key
)
,
and
f
[
key
].value
is a list of values, getfirst
returns
f
[
key
].value[0]
.
When key
is not a key in
f
, getfirst
returns
default
.
Use getfirst
when you know that there should be
just one input field (or at most one input field) named
key
in the form from which your
script’s input comes. getfirst
was introduced in Python 2.2, so don’t use it if
your script must remain compatible with older versions of Python.
Get Python in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.