2009-09-30, 07:09 PM
Devil's Sunrise Wrote:I really hate Python at dictionaries there though. dict[key] raises KeyError when key is missing. asdf.
There's a way around that.
value = dict.get(keyName, defaultValue)
So...
Dict = {'1':'my value'}
value = Dict.get('1', 'NULL') #Returns 'my value'
value = Dict.get('2', 'NULL') #Returns 'NULL'
Or you can do...
Code:
if key in Dict:
#Do something
else:
#do something elseNo try/except required.

ALL Python code I write has try/catch exceptions as a last resort because I consider it to be poor programming.
