Ternary operator alternative in Ptyhon

William Heymann kosh at aesaeion.com
Wed Jun 18 08:31:17 CEST 2008

On Wednesday 18 June 2008, kretik wrote:

>      if params.has_key("mykey"):
>          self.SomeField = params["mykey"]
>      else:
>          self.SomeField = None

self.SomeField = parms.get('mykey', None)

This looks like what you want and it is also simpler because you don't deal 
with checking if the key exists. 

More information about the Python-list mailing list