What is the Pythonic way to do this?
value = (mydict.has_key('index') and mydict['index']) or 1024
Initialize from a dict’s value, if present, otherwise use default value.
Got some answers on LBYL and EAFP, but too verbose code :p
I want some one-line-initialize.
PS: python-2.4 only (running CentOS5)
(Note that this is not exactly equivalent to your code, since it will use
1024only if the keyindexis not present, while your code also uses1024when the value corresponding to keyindexis falsy. From your explanation I infer the former is what you actually want.)