Re: [orca-list] A question for a traceback error message prewenting related
- From: Joanmarie Diggs <joanied gnome org>
- To: Hammer Attila <hammera pickup hu>
- Cc: orca-list gnome org
- Subject: Re: [orca-list] A question for a traceback error message prewenting related
- Date: Tue, 01 Nov 2011 03:48:39 -0400
Hey Attila.
[...]
File "/usr/lib/python2.6/dist-packages/orca/orca_gui_prefs.py", line
1830, in _initGUIState
prefs["showcursorComputerBraille"])
KeyError: 'showcursorComputerBraille'
So, this traceback error message happening if not existing in
user-settings.conf file the showCursorComputerBraille setting.
Right. You can either catch that exception or you can prefer using get()
if you want to look up a value in a dictionary which might not have that
key.
The former would look something like:
try:
myValue = myDictionary['myKey']
except KeyError:
# Here is where you put what should happen if that key is not
# found. If you can safely set myValue to some default and
# happily continue working after that, here's where you would
# set it. Like:
myValue = 42
else:
# This part may or may not be needed. Depends on how you
# handle the exception and what (if anything) you might
# need to do in case you got the value you needed when
# you tried. If you don't need to do anything here, just
# don't include the else.
print "Yay! No error"
The latter/alternative would look like this:
myValue = myDictionary.get('myKey')
In that case, if there is no key called myKey, you cannot obtain its
value. As a result, myValue will be set to None. And then you must be
sure to handle that case. In other words, if you try to do something
with myValue and myValue is None, there's an excellent chance you'll get
a traceback.
If there is some default value that will work, you can optionally
provide it. For instance:
myValue = myDictionary.get('myKey', 42)
In that case, if there's a value to be had, you'll get it. If that key
doesn't exist, myValue will get set to 42.
Make sense?
Take care.
--joanie
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]