2009-09-30, 07:49 PM
Fiel Wrote:There's a way around that.Oh, I know. But dict[key] should return null/nil when key's not found!
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 else
No try/except required.
ALL Python code I write has try/catch exceptions as a last resort because I consider it to be poor programming.

Also...


