Skip to content

Commit

Permalink
Merge pull request #1522 from hoechenberger/exp-handler
Browse files Browse the repository at this point in the history
FF, DOC: Don't hard-code CSV field separator in `ExperimentHandler.close()`
  • Loading branch information
peircej committed Sep 20, 2017
2 parents e563252 + 2349e9f commit 9d30a54
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions psychopy/data/experiment.py
Expand Up @@ -232,7 +232,9 @@ def nextEntry(self):
self.entries.append(this)
self.thisEntry = {}

def saveAsWideText(self, fileName, delim=None,
def saveAsWideText(self,
fileName,
delim=None,
matrixOnly=False,
appendFile=False,
encoding='utf-8',
Expand All @@ -249,12 +251,31 @@ def saveAsWideText(self, fileName, delim=None,
which can be handy if you want to append data to an existing file
of the same format.
encoding:
The encoding to use when saving a the file. Defaults to `utf-8`.
:Parameters:
fileCollisionMethod:
Collision method passed to
:func:`~psychopy.tools.fileerrortools.handleFileCollision`
fileName:
if extension is not specified, '.csv' will be appended if
the delimiter is ',', else '.tsv' will be appended.
Can include path info.
delim:
allows the user to use a delimiter other than the default
tab ("," is popular with file extension ".csv")
matrixOnly:
outputs the data with no header row.
appendFile:
will add this output to the end of the specified file if
it already exists.
encoding:
The encoding to use when saving a the file.
Defaults to `utf-8`.
fileCollisionMethod:
Collision method passed to
:func:`~psychopy.tools.fileerrortools.handleFileCollision`
"""
# set default delimiter if none given
Expand Down Expand Up @@ -335,12 +356,12 @@ def saveAsPickle(self, fileName, fileCollisionMethod='rename'):
def close(self):
if self.dataFileName not in ['', None]:
if self.autoLog:
logging.debug(
'Saving data for %s ExperimentHandler' % self.name)
if self.savePickle == True:
msg = 'Saving data for %s ExperimentHandler' % self.name
logging.debug(msg)
if self.savePickle:
self.saveAsPickle(self.dataFileName)
if self.saveWideText == True:
self.saveAsWideText(self.dataFileName + '.csv', delim=',')
if self.saveWideText:
self.saveAsWideText(self.dataFileName + '.csv')
self.abort()
self.autoLog = False

Expand Down

0 comments on commit 9d30a54

Please sign in to comment.