Convert psydat to csv file / cannot open a psydat file

Hi all. My experiment was created with Builder 3.2.2, running on macOS Mojave 10.14.4. I’m very new to coding in Python, please bear with me. For one full experiment, only one csv file was created out of 12 participants : for the other participants, a psydat file was issued for each. I tried loading the psydat files with psychopy.misc.fromFile in the coder view and in Terminal running in Python, but I get the “No such file or directory” error. What am I doing wrong?
Thanks a lot for your help.

Running: /Users/p43547/Applications/PsychoPy3.app/Contents/Resources/lib/python3.6/psychopy/demos/coder/csvFromPsydat.py

psydat: /Users/p43547/Applications/PsychoPy3.app/Contents/Resources/lib/python3.6/psychopy/demos/coder/fileName.psydat
Traceback (most recent call last):
File “/Users/p43547/Applications/PsychoPy3.app/Contents/Resources/lib/python3.6/psychopy/demos/coder/csvFromPsydat.py”, line 20, in
exp = fromFile(file_psydat)
File “/Users/p43547/Applications/PsychoPy3.app/Contents/Resources/lib/python3.6/psychopy/tools/filetools.py”, line 54, in fromFile
with open(filename, ‘rb’) as f:
FileNotFoundError: [Errno 2] No such file or directory: ‘/Users/p43547/Applications/PsychoPy3.app/Contents/Resources/lib/python3.6/psychopy/demos/coder/fileName.psydat’

Hi again! I was not able to recover the file, even if I wrote the good path and even when following this script : Data outputs — PsychoPy v2021.2.4. I will be grateful for any help! Thanks.

Hi There,

Have you tried the “csvFromPsyDat” demo in the coder of the newest release (2021.2.3)?

Thanks,
Becca

Hi Becca,
I tried it with the following script and it worked! Still don’t know what I was doing wrong earlier. Thanks a lot for your help.
Rosalie

"""utility for creating a .csv file from a .psydat file

edit the file name, then run the script
"""
from __future__ import print_function

import os
from psychopy.tools.filetools import fromFile

# EDIT THE NEXT LINE to be your .psydat file, with the correct path:
name = '/Users/p47/Desktop/nameofthefile.psydat'

file_psydat = os.path.abspath(name)
print("psydat: {0}".format(file_psydat))

# read in the experiment session from the psydat file:
exp = fromFile(file_psydat)

# write out the data in .csv format (comma-separated tabular text):
if file_psydat.endswith('.psydat'):
    file_csv = file_psydat[:-7]
else:
    file_csv = file_psydat
file_csv += '.csv'
exp.saveAsWideText(file_csv)

print('-> csv: {0}'.format(os.path.abspath(file_csv)))```

Hi Rosalie,

Splendid!! if this answered your question please do mark the response that solved the problem with “solution” so that future users know!

Thanks!
Becca

1 Like