Howdy, Stranger!

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

Supported by

[open] Is it possible to save variables to a file outside of the logger?

edited September 2014 in OpenSesame

Hi there! This is a follow up post to my earlier one from last week

(http://www.cogsci.nl/forum/index.php?p=/discussion/1116/solved-how-to-use-items-in-a-list-as-variables#Item_7)

The short version:
With help of this site I was able to import a text file as a string of words, store it as a python variable called word_list using numpy, randomize the list, and loop through it to present each word on a screen. I then stored the words as an experiment variable [word]. My only issue now is that when I try to reuse this python variable word_list in a different loop later on, OpenSesame no longer recognizes the python variable word_list. I tried globalizing word_list but that did not seem to work either.

I was wondering if it is possible to store the words presented on the screen from the first loop in a new text file (not the logger) and reread this into the second loop. It is very important that I can gain access to the exact same words because the subjects are being tested on them. (Study phase in the first loop, test phase mixed with old and new words in subsequent loops).

I appreciate the help I have received from this forum!

Thank you :)

Comments

  • edited 7:04AM

    Hi,

    If you want to write your words to a temporary file, you could do this as follows. First, before the training block, open a file (my_file) in write mode.

    import os
    my_path = os.path.join(exp.pool_folder, 'my_file.txt')
    my_file = open(my_path, 'w')
    

    At the end of the trial, write the current word to the file. Here we assume that this word is stored as an experimental variable with the name word. Note the \n character. This a line separator, which you need to explicitly add to avoid getting a single long line of text.

    my_file.write(self.get('word') + '\n')
    

    Then, after the training block is finished, close the file.

    my_file.close()
    

    So that's quite easy, really. For more information about files in Python, see:

    That being said, wouldn't it be even easier to store the words in a list? Then you would create an empty list before the training block ...

    my_list = []
    

    ... and add the words like this ...

    my_list.append(self.get('word'))
    

    Both methods are possible, but the list way is a bit simpler.

    Cheers!
    Sebastiaan

  • edited 7:04AM

    Thank you again! The only issue I keep having is that when I create a new inline code in my second loop, OpenSesame no longer recognizes my_list and tells me it doesn't exist (the red arrow appears while typing- 'undefined my_list'). Is placement within loops the issue? Where should I place all this code? Also, when I save word to a temporary file, it only loads the very last word of the sequence and that word alone.

    Would it be more helpful if I outlined my experiment?

  • edited 7:04AM

    The only issue I keep having is that when I create a new inline code in my second loop, OpenSesame no longer recognizes my_list and tells me it doesn't exist (the red arrow appears while typing- 'undefined my_list').

    The code validation only checks inline_script on their own. Therefore, if you refer to names that have been defined elsewhere you will get a warning. But unless you actually experience a crash, that's no problem. You can disable validation in the preferences of the editor component. (It's disabled by default as of 2.9.0, for precisely this reason.)

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