I am trying to create a simple output file containing a timestamp (of when the stimulus appears) and the colour of the stimuli.
I am able to write a file with just the colours, however whenever I try to create a file with both the timestamp and the colour I get an error. "TypeError: cannot concatenate 'str' and 'datetime.datetime' objects"
Code below:
from psychopy import visual, core
import random
import time
import datetime
import time
from time import strftime
f = open('2015-07-15-Random-Output.txt', 'w')
print f
file = open ('2015-07-15-Random-Output.txt', 'w')
win = visual.Window([800,800],monitor="testmonitor", units="deg")
HolaMundo = "Hola Mundo"
for frameN in range(10):
MyColor = random.choice(['red','blue','green','pink','purple','orange','yellow','black','white'])
time = datetime.datetime.now()
print time
data = MyColor + str(time)
msg = visual.TextStim(win, text=HolaMundo,pos=[-4,0],color=MyColor)
msg.draw()
win.flip()
core.wait(.1)
datetime.datetime.now
file.write(time + '\n')
file.close()