Howdy, Stranger!

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

Supported by

[solved] Custom log file error

edited November 2015 in OpenSesame

Hi,

Im working on a simple Stroop task with a Droid back-end and instead of the standard logger i want to use a custom log file with just a couple of variables. I use one inline_script at the start of the experiment that closes the log file and creates a new one with an updated participant number and begin by writing the header of the new file:

import codecs
import os
print log
# Close current log file
log.close()

# Define the first log
i = 0

print os.path.dirname(os.path.realpath('.'))

while os.path.exists('/sdcard/Data/Stroop/subject-%d.csv' % i):
    i += 1
    print i
# Open the new log file with up to date participant number
log = codecs.open('/sdcard/Data/Stroop/subject-%d.csv' % i, 'w', encoding='utf-8')
print log

# write header to log
log.write("word,color,congruency,rt/n")

Then after the response for each trial i put another inline_script to write the variables i'm interested in according to the new syntax documentation:

var_list = [var.word,var.color,var.congruency]

log.write_vars(var_list)

However, the script crashes after the first trial and the newly made log file remains empty. The debug text states that the 'file' object has no attribute 'write_vars'

Does anyone see what is going wrong?

Thanks in advance,

Laurent

Comments

  • edited 4:19PM

    Hi Laurent,

    codecs.open() returns a file object, which supports all the regular Python file operations. But you're treating it as though it's an OpenSesame log object (i.e. by calling log.write_vars()). The correct approach would be to either:

    1. Create a file object, as you're doing now, and use the standard operations, as described here:
    2. Re-open the OpenSesame log object, using log.open() as described here:

    Does that make sense?

    Cheers,
    Sebastiaan

  • edited 4:19PM

    Hi Sebastiaan,

    Thanks for the quick reply, it makes more sense now. What remains is a beginners question: How can i write the variables to the new log file? At the moment i create a list like in the previous post and i use log.write_vars([var_list]) to write the values to the file but this results in the following error: 'list' object has no attribute 'replace'

    Am i missing something in the syntax here?

    On a related note, in another experiment made with the previous version of OpenSesame i used a very similar customized log file; i create a new file object, write a header to it and gather the variables. Here i write the variables with

    self.log('%s', % (self.get('var1'))) 
    

    and it used to work perfectly. But with the new 3.0.1 version i get the folowing error: StreamReaderWriter instance has no call method

    Could this be a result of the new version?

    • Laurent
  • edited 4:19PM

    At the moment i create a list like in the previous post and i use log.write_vars([var_list]) to write the values to the file but this results in the following error: 'list' object has no attribute 'replace'

    var_list is already a list, so you don't need to put brackets around it; that will just put the list in another list.

    On a related note, in another experiment made with the previous version of OpenSesame i used a very similar customized log file; i create a new file object, write a header to it and gather the variables. Here i write the variables with self.log('%s', % (self.get('var1'))) and it used to work perfectly. But with the new 3.0.1 version i get the folowing error: StreamReaderWriter instance has no call method

    This is essentially the same problem as before. You've replaced the a standard log object with a StreamReaderWriter, which doesn't support calling the object directly--which happens here, because self.log is an object, not a function.

    This may sound complicated, but as a general simple rule, OpenSesame's standard objects are a bit like Britney, you gotta leave them alone. So don't replace log, pool, var, items, clock, etc. If you want to create your own logfile through codecs, that's fine, but you should simply assign it to a different variable. For example, this is fine:

    # Open the new log file with up to date participant number
    my_custom_log = codecs.open('/sdcard/Data/Stroop/subject-%d.csv' % i, 'w', encoding='utf-8')
    

    Makes sense?

  • edited 4:19PM

    This may sound complicated, but as a general simple rule, OpenSesame's standard objects are a bit like Britney, you gotta leave them alone.

    Excellent explanation, it makes sense now =)

    I've decided to stick with creating file objects as new log files and with some minor alterations both work fine now but i still don't understand why the logging stopped working in the first place.

    Btw, i discovered the live variable inspector today, it makes tracking the errors a lot easier. Great new feature!

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