写全宇宙最简单的python,遇到这个错误:
C:\miniconda3\envs\p2\python.exe C:/Users/livingbody/PycharmProjects/aistudio_getscore/main.py Traceback (most recent call last): File "C:\Users\livingbody\PycharmProjects\aistudio_getscore\main.py", line 68, in <module> save_json('result.csv', point) File "C:\Users\livingbody\PycharmProjects\aistudio_getscore\main.py", line 61, in save_json f.write(key, +'\t' + data[key] + '\n') TypeError: bad operand type for unary +: 'str'
惊呆了老铁,为啥啊,仔细一看原来如此:
def save_json(filename, data): f = open(filename, 'w') for key in data.keys(): f.write(key, +'\t' + data[key] + '\n') f.close()
字符串相加时多了额外的逗号,哭晕了,基础不牢,地动山摇啊。