Welcome!

Sign in with your CogSci, Facebook, Google, or Twitter account.

Or register to create a new account.

We'll use your information only for signing in to this forum.

Supported by

Python code

I have this code to generate a random ID and it seems to work:
import uuid
print uuid.uuid4().hex[:16].upper()

How do I write the result from the inline script to the logger? The result only prints on the prepare page, not the run page and when I run the code, the experiment goes straight to my "Welcome screen". My python inline script is before the Welcome Screen.

I also need to input the experiment code so can I code an input in the same inline script and output both the experiment code (which stays the same for each experiment) and the unique participant code.

Comments

  • eduardeduard Posts: 1,043

    Hi,

    You have to capture the output of the function in a variable:

    import uuid
    var.ID =  uuid.uuid4().hex[:16].upper() # save the code
    print var.ID # print the code
    

    I also need to input the experiment code so can I code an input in the same inline script and output both the experiment code (which stays the same for each experiment) and the unique participant code.

    I'm not sure whether I understand. If you have a unique experiment code that doesn't change across participants, then you can just set it in the beginning of your script, e.g.

    import uuid
    var.ID =  uuid.uuid4().hex[:16].upper() # save the code
    print var.ID # print the code
    # set experiment code
    var.experimentCode = 10 # or whatever you want the code to be
    

    Or did you mean anything else?

    Does that all make sense?

    Eduard

  • Hey Eduard (and Happy New Year),
    I think the problem is that I don't know exactly what the logger captures. And part of that problem is that the variables are difficult to see in the sidebar or topbar. Is there a way to print these out or copy them to an excel file?
    Thanks for added information to the inline script. I thought it might be that but I wasn't sure because of my logger confusion.

  • eduardeduard Posts: 1,043

    Hi, printing them out is very easy. In the code of my previous code I have a line that starts with print that will print it to the debug window (activate it with ctrl+D). If you run your experiment, you can check the logfile that is written to look at the variables. But that only works after testing your experiment, not online.

    Eduard

  • This all works in the new version too. Thanks for your help. This discussion can be closed.
    Is there a place we can put out closed discussions so I know which ones are still active?

  • eduardeduard Posts: 1,043

    Generally, we don't close discussions, because maybe some other person will have a closely related question at some point in the future. If nobody is posting into discussion, they will just sink down the list.

  • But the discussion stays in "My Discussions" so I was wondering if there was a way to clear out the ones that have been resolved?

Sign In or Register to comment.