From f44a5e33bf8d194931f200c7d84fadc5755091c9 Mon Sep 17 00:00:00 2001 From: Malte Persike Date: Wed, 19 Sep 2018 13:11:38 +0200 Subject: [PATCH] ENH: ExperimentHandler.saveAsWideText() has a new parameter "sortedColumns" which has header names sorted alphabetically when storing data in a text file. This guarantees a predictable order of columns in the stored csv/tsv files. --- psychopy/data/experiment.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/psychopy/data/experiment.py b/psychopy/data/experiment.py index 5b8178fbbc..7dcc219509 100644 --- a/psychopy/data/experiment.py +++ b/psychopy/data/experiment.py @@ -252,7 +252,8 @@ def saveAsWideText(self, matrixOnly=False, appendFile=False, encoding='utf-8', - fileCollisionMethod='rename'): + fileCollisionMethod='rename', + sortColumns=False): """Saves a long, wide-format text file, with one line representing the attributes and data for a single trial. Suitable for analysis in R and SPSS. @@ -291,6 +292,9 @@ def saveAsWideText(self, Collision method passed to :func:`~psychopy.tools.fileerrortools.handleFileCollision` + sortColumns: + will sort columns alphabetically by header name if True + """ # set default delimiter if none given if delim is None: @@ -306,6 +310,9 @@ def saveAsWideText(self, names.extend(self.dataNames) # names from the extraInfo dictionary names.extend(self._getExtraInfo()[0]) + # sort names if requested + if sortColumns: + names.sort() # write a header line if not matrixOnly: for heading in names: