ヘルプが必要です。 データリストarglist、例: ['dlink'、 'des'、 '1210'、 'c'、24] < - これは「印刷」ビューです。Python TypeError:予想される文字列またはバッファー
そして、このコード:
sw_info ={"Brand":arglist[0],
"Model":arglist[1],
"Hardware":arglist[2],
"Software":arglist[3],
"Portsnum":arglist[4]}
print json.dumps(sw_info, open("test", "w"))
z = json.loads(open("test", "r"))
print s
それが与える:
Traceback (most recent call last):
File "parsetest.py", line 34, in <module>
z = json.loads(open("test", "r"))
File "/usr/lib64/python2.6/site-packages/simplejson/__init__.py", line 307, in loads
return _default_decoder.decode(s)
File "/usr/lib64/python2.6/site-packages/simplejson/decoder.py", line 335, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
TypeError: expected string or buffer
いただきましたの?
文字列ではなくファイルオブジェクトを '読み込み 'しようとしています。文字列ではなくファイルで作業する場合は、 'json.load'と' json.dump'を使うだけです。 – geoffspear
デバッグの最初のルールは、エラーがあなたに文字どおりの真実を伝えていると仮定することです。それは文字列を期待しているが、あなたはそれを与えていない。だから、なぜ文字列ではないものを渡しているのか、何か他のものがあるときには文字列を必要とする関数を使用している理由で調査を開始してください。 –
そうです。とても明らかです。手伝ってくれてありがとう。 – Jetpylot