Ternary operator alternative in Ptyhon

Jeffrey Froman jeffrey at fro.man
Wed Jun 18 16:54:01 EDT 2008


jeremie fouche wrote:

> You can also use :
> self.SomeField = params.has_key("mykey") and params["mykey"] or None

Have caution with this solution: it may not provide the desired result in
the case where params["mykey"] is a false value, such as 0, or []


Jeffrey



More information about the Python-list mailing list