Skip to content

Commit 9a4a038

Browse files
committed
BF: manual fix for csv writing in example
Use manual fix for Python 2 / 3 differences for clarity in example.
1 parent 83a8082 commit 9a4a038

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

examples/labs/write_paradigm_file.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
88
See Pinel et al., BMC neuroscience 2007 for reference
99
"""
10+
import sys
1011
import csv
1112

1213
import numpy as np
@@ -45,7 +46,11 @@
4546
sess = np.zeros(np.size(time)).astype('int8')
4647
pdata = np.vstack((sess, cid, time)).T
4748
csvfile = 'localizer_paradigm.csv'
48-
fid = open(csvfile, "wt")
49+
# Opening files for CSV writing differs between Python 2 and 3
50+
if sys.version_info[0] >= 3: # Python 3
51+
fid = open(csvfile, "w", newline = '')
52+
else: # Python 2
53+
fid = open(csvfile, "wb")
4954
writer = csv.writer(fid, delimiter=' ')
5055
for row in pdata:
5156
writer.writerow(row)

0 commit comments

Comments
 (0)