Ternary operator alternative in Ptyhon

William Heymann kosh at aesaeion.com
Wed Jun 18 02:31:17 EDT 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