我有以下功能:
def readTable(self,reference_name):
p = self.base_path + reference_name + ".txt"
if os.path.exists(p):
print p
else:
print "oops"
f = open(p, "r")
data = json.loads(f.read())
self.main_table = data
告诉我文件确实存在,并且正在尝试读取包含json的txt文件。
json由以下调用编写:
def writeTable(table,reference_name):
with open(reference_name + ".txt","w") as text_file:
json.dump(table, text_file)
然而,当我转到readTable
时,我收到以下错误:
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm 4.0.5\helpers\pydev\pydevd_comm.py", line 1069, in doIt
result = pydevd_vars.evaluateExpression(self.thread_id, self.frame_id, self.expression, self.doExec)
File "C:\Program Files (x86)\JetBrains\PyCharm 4.0.5\helpers\pydev\pydevd_vars.py", line 341, in evaluateExpression
Exec(expression, updated_globals, frame.f_locals)
File "C:\Program Files (x86)\JetBrains\PyCharm 4.0.5\helpers\pydev\pydevd_exec.py", line 3, in Exec
exec exp in global_vars, local_vars
File "<string>", line 1, in <module>
File "C:\Users\user\AppData\Local\Continuum\Anaconda\lib\json\__init__.py", line 338, in loads
return _default_decoder.decode(s)
File "C:\Users\user\AppData\Local\Continuum\Anaconda\lib\json\decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\user\AppData\Local\Continuum\Anaconda\lib\json\decoder.py", line 384, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
文件中的数据如下所示:
[12.7451, 0.774784, 3.422666, 1.21522, 0.918463, 630.693, 6.37, 6.263, 2479.94, 555.475, 24.3585, 6.619372, 8.58075, 1.12385, 1.555879, 7.75208, 274.995, 14458.4, 3.8407999999999998, 68.25702, 119.12, 104.5, 1105.223, 10.1126, u'', 15.8013, 3.7115, 7.612444, 0.71116, 3.34583, 45.645, 3.6949300000000003, 57.5855, 8.22703, 1.3449900000000001, 26.80494, 34.639, 2.95794, 30.6675, u'', 12.86649]