Howdy, Stranger!

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

Supported by

how to work with unicode input from keyboard_response?

I use two keyboard_response objects to log two responses (for an identification task for two letters shown in the trial), and I then want to determine whether the letter matched any of the two letters shown, to create a score for each letter as having been seen or not.

To do so, I tried comparing the logged keyboardinput to the target letter, but there is a mismatch in case: Target is uppercase, this response is encoded in lowercase (turning on caps lock during run time does not help).

If I use str.upper(var.letterinput) to convert the input into uppercase, it says "exception message: descriptor 'lower' requires a 'str' object but received a 'unicode' "

Does anyone know how I can change the unicode encoding into string / compare an uppercase target letter to a lowercase input letter?

Comments

  • Hi Mark,

    upper() is a method of a str or unicode object (which are both text objects) and you call them like so:

    var.letterinput.upper()
    

    So you call the method on the object, and don't pass the object as an argument. Does that clear things up?

    So checking whether a response was correct would look something like this:

    var.correct = 1 if var.letterinput.upper() == var.target_letter else 0
    

    Cheers!
    Sebastiaan

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

  • Thanks for the quick and early response, works like a charm!

Sign In or Register to comment.