Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Turkish character Key error

edited April 2016 in OpenSesame

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

  • edited 7:48AM

    This error comes from your own inline script, so could you please post that script here?

    Cheers,
    Sebastiaan

  • edited April 2016

    Hey, sorry for the late reply, here is my inline script I think the problem occurs.

    {"main-item-name": "selectItemAndDetermineTrialType", "type": "item-snippet", "items": [{"item-type": "inline_script", "item-name": "selectItemAndDetermineTrialType", "script": "define inline_script selectItemAndDetermineTrialType\n\tset description \"Executes Python code\"\n\tset _run \"\"\n\t___prepare__\n\t\n\t
    
    ## Select the current item:\n\tcurItem = curItems[0]\n\t\n\t
    ## Remove this item for the to be studied items, as the participant might\n\t
    ## answer it correctly.\n\tcurItems.remove(curItem)\n\t\n\t
    ## Figure out whether we already presented this item. If so, present a test\n\t
    ## trial, if not, present a study trial *and* make sure that next time round\n\t
    ## we'll present it as a study trial.\n\t
    
    if (curItem in itemsPresented):\n\t\t
    trialType = 'test'\n\telse:\n\t\ttrialType = 'study'\n\t\t
    
    curItems.append(curItem)\n\t\t
    
    itemsPresented.append(curItem)\n\t\n\t
    var.cue = curItem\n\tvar.response = allItems[curItem]\n\t
    
    var.trialType = trialType\n\t
    
    __end__\n"}]}
    
  • edited 7:48AM

    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.

  • edited April 2016

    Hi,

    In general, the KeyError indicates 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:

    curItem = curItems[0]
    

    or

    var.response = allItems[curItem]
    

    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

  • edited 7:48AM

    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

  • edited 7:48AM

    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.

  • edited 7:48AM

    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

  • edited 7:48AM

    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

  • edited 7:48AM

    Hi Turco,

    @jarik is correct. What happens is the following:

    • You have defined the keys of the dictionary as str objects; that is, the strings do not have the u suffix. When working with non-ascii characters, this is asking for trouble. Golden rule: always prefix text with u!
    • Then, when the participant makes a mistake, the to-be-repeated item is set as an experimental variable.
    • OpenSesame automatically converts this variable from a str into a unicode object.
    • Finally, when using the unicode key to look up a value in the dictionary, the key doesn't match, because the dictionary has str keys. Result: a KeyError.

    Long story short: Make sure that you're only working with unicode objects by prefixing a u to all strings in your script.

    Cheers!
    Sebastiaan

  • edited 7:48AM

    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

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games