问题
this is a function of counting sentimental score of each syntax and i am getting this error
Traceback (most recent call last):
File "C:/Users/Public/Downloads/Hotelsurvey.py", line 116, in <module>
Countswordofeachsyntax()
File "C:/Users/Public/Downloads/Hotelsurvey.py", line 92, in Countswordofeachsyntax
print(findsentimentalscore(nopunct))
File "C:/Users/Public/Downloads/Hotelsurvey.py", line 111, in findsentimentalscore
ss =ss + weight
TypeError: unsupported operand type(s) for +: 'int' and 'list'
def Countswordofeachsyntax():
nopunct = ""
with open('dataset-CalheirosMoroRita-2017.csv', 'r') as csv_file:
csv_reader = csv.reader(csv_file, delimiter='|')
for sys in csv_reader:
for value in sys:
nopunct = ""
for ch in value:
if ch not in punctuation:
nopunct = nopunct + ch
print(findsentimentalscore(nopunct))
回答1:
It seams like you are trying to add a int to a list in ss = ss+weight, maybe try typecasting ss to a integer as i suspect you want a number instead of what is possibly a sting, but if you can update your question with the code for findsentimentalscore() where problem seam to be, then that would make it easier to locate the actual problem.
okay from the edit you suggested it might be weight that is the problem, try this ss = ss + int(weight)
来源:https://stackoverflow.com/questions/62657944/i-am-trying-to-calculate-sentimental-score-of-each-syntax-of-csv-file