Spyder 在读取 file/running csv 函数时挂起
Spyder hang while reading a file/running csv function
我不太明白是什么导致我的这个脚本挂起(即整个 spyder 停止工作)。是否与我的代码有关,或者我的某些 Spyder/python 文件已损坏?
#Import relevant modules
import os
import numpy as np
import csv
C1adaptS = 0
CN2adaptS = 0
N3adaptS = 0
NS4adaptS = 0
S5adaptS = 0
C1adaptC = 0
CN2adaptC = 0
N3adaptC = 0
NS4adaptC = 0
S5adaptC = 0
#Paste filename to be analysised here (The .csv file)
filename = 'PartID_WK_plottest.xls'
#Change directory to file's location
os.chdir('C:\Users\Aaron\Desktop\Experiments\Dotty_Simplified_(FINAL)')
loadcsv = open(filename, 'r')
for line in loadcsv.readlines():
line = line.strip()
#Split the words within the line
trialnum, stimulus, stimulus_location, response, more_sin_like, sin_adapt = line.split(',')
if stimulus == 'C1' and more_sin_like == 1 and sin_adapt == 1:
C1adaptS += 1
elif stimulus == 'CN2' and more_sin_like == 1 and sin_adapt == 1:
CN2adaptS += 1
elif stimulus == 'N3' and more_sin_like == 1 and sin_adapt == 1:
N3adaptS += 1
elif stimulus == 'NS4' and more_sin_like == 1 and sin_adapt == 1:
NS4adaptS += 1
elif stimulus == 'S5' and more_sin_like == 1 and sin_adapt == 1:
S5adaptS += 1
elif stimulus == 'C1' and more_sin_like == 1 and sin_adapt == 0:
C1adaptC += 1
elif stimulus == 'CN2' and more_sin_like == 1 and sin_adapt == 0:
CN2adaptC += 1
elif stimulus == 'N3' and more_sin_like == 1 and sin_adapt == 0:
N3adaptC += 1
elif stimulus == 'NS4' and more_sin_like == 1 and sin_adapt == 0:
NS4adaptC += 1
elif stimulus == 'S5' and more_sin_like == 1 and sin_adapt == 0:
S5adaptC += 1
print C1adaptS
print CN2adaptS
print N3adaptS
print NS4adaptS
print S5adaptS
print C1adaptC
print CN2adaptC
print N3adaptC
print NS4adaptC
print S5adaptC
如果真的是代码错误,也许敏锐的眼睛可以发现问题。我好像什么都捡不到。
也许有
#Paste filename to be analysed here (The .csv file)
filename = 'PartID_WK_plottest.xls'
文件名以“.xls”结尾,因此它可能不是 CSV 文件。之后,您尝试像阅读文本文件一样阅读它。
我不太明白是什么导致我的这个脚本挂起(即整个 spyder 停止工作)。是否与我的代码有关,或者我的某些 Spyder/python 文件已损坏?
#Import relevant modules
import os
import numpy as np
import csv
C1adaptS = 0
CN2adaptS = 0
N3adaptS = 0
NS4adaptS = 0
S5adaptS = 0
C1adaptC = 0
CN2adaptC = 0
N3adaptC = 0
NS4adaptC = 0
S5adaptC = 0
#Paste filename to be analysised here (The .csv file)
filename = 'PartID_WK_plottest.xls'
#Change directory to file's location
os.chdir('C:\Users\Aaron\Desktop\Experiments\Dotty_Simplified_(FINAL)')
loadcsv = open(filename, 'r')
for line in loadcsv.readlines():
line = line.strip()
#Split the words within the line
trialnum, stimulus, stimulus_location, response, more_sin_like, sin_adapt = line.split(',')
if stimulus == 'C1' and more_sin_like == 1 and sin_adapt == 1:
C1adaptS += 1
elif stimulus == 'CN2' and more_sin_like == 1 and sin_adapt == 1:
CN2adaptS += 1
elif stimulus == 'N3' and more_sin_like == 1 and sin_adapt == 1:
N3adaptS += 1
elif stimulus == 'NS4' and more_sin_like == 1 and sin_adapt == 1:
NS4adaptS += 1
elif stimulus == 'S5' and more_sin_like == 1 and sin_adapt == 1:
S5adaptS += 1
elif stimulus == 'C1' and more_sin_like == 1 and sin_adapt == 0:
C1adaptC += 1
elif stimulus == 'CN2' and more_sin_like == 1 and sin_adapt == 0:
CN2adaptC += 1
elif stimulus == 'N3' and more_sin_like == 1 and sin_adapt == 0:
N3adaptC += 1
elif stimulus == 'NS4' and more_sin_like == 1 and sin_adapt == 0:
NS4adaptC += 1
elif stimulus == 'S5' and more_sin_like == 1 and sin_adapt == 0:
S5adaptC += 1
print C1adaptS
print CN2adaptS
print N3adaptS
print NS4adaptS
print S5adaptS
print C1adaptC
print CN2adaptC
print N3adaptC
print NS4adaptC
print S5adaptC
如果真的是代码错误,也许敏锐的眼睛可以发现问题。我好像什么都捡不到。
也许有
#Paste filename to be analysed here (The .csv file)
filename = 'PartID_WK_plottest.xls'
文件名以“.xls”结尾,因此它可能不是 CSV 文件。之后,您尝试像阅读文本文件一样阅读它。