Turkish character Key error
Hi,
I am having trouble with running Turkish characters. The experiment presents a number of trials with many Turkish characters without problem, however at the end of a sequence it gives Key error and states the Unicode of the character that caused the bug. Here is the detail provided by the program.
item-stack: experiment[run].runBlock[run].blockSequence[run].untilCurrentStackIsEmpty[run].selectAndPresentItem[prepare].selectItemAndDetermineTrialType[prepare]
exception type: KeyError
exception message: u'g\xfcne\u015f'
item: selectItemAndDetermineTrialType
time: Fri Apr 22 15:03:36 2016
phase: prepare
Comments
This error comes from your own inline script, so could you please post that script here?
Cheers,
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hey, sorry for the late reply, here is my inline script I think the problem occurs.
I guess I managed to learn pastebin, so this is the inline script that causes trouble.
http://pastebin.com/pKpgmr6X
Thanks in advance for any help offered.
Hi,
In general, the
KeyErrorindicates that you're trying to get something from a dict or a list using a key that doesn't exist. It seems likely that one of these lines is the culprit:or
However, where the error comes from exactly is not clear from this script, because the experiment presumably contains more scripts in which
curItems,itemsPresented, etc. are defined.I have the impression that you did not create this experiment yourself, is that correct? If not, perhaps you could ask the original creator what the problem is? Or you could post the full experimental script here, and we can try to figure out the problem.
Cheers,
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
My supervisor created the scripts, unfortunately I have very limited knowledge on programming. The problem is, he is away for 2 weeks and the study begins next week. Well, here is the full script including the explanation of what the program is supposed to do. I owe you big time.
Regards,
Turco
http://pastebin.com/Bk53rjTt
Maybe I was not clear enough but the script runs and the words in the list are presented multiple times successfully. Error occurs when a new trial is about to be defined and it seems to occur completely at random, for example for items that are presented successfully in an earlier trial and for different items each time. It happens only at the end of trials when the presentation and response to 6 items for that trial is completed.
This is the screenshot of the problem when experiment stops, maybe it can give a clue.
https://www.dropbox.com/s/25rdhkw8nybhsjj/Key-error.png?dl=0
Hi turco,
Turn all the words into unicode by prefixing u (see image below).
More info by Sebastiaan here:
http://www.cogsci.nl/blog/miscellaneous/245-a-simple-explanation-of-character-encoding-in-python
Best,
Jarik
Hi Turco,
@jarik is correct. What happens is the following:
strobjects; that is, the strings do not have theusuffix. When working with non-ascii characters, this is asking for trouble. Golden rule: always prefix text withu!strinto aunicodeobject.unicodekey to look up a value in the dictionary, the key doesn't match, because the dictionary hasstrkeys. Result: aKeyError.Long story short: Make sure that you're only working with
unicodeobjects by prefixing auto all strings in your script.Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Thank you both very much Jarik and Sebastiaan!
I converted the items and now it runs smoothly. Now I can collect data on time. I wish you both a very nice week.
Kind regards,
Turco