0
私は5,693回回帰を実行し、実行に数時間かかったので出力を保存したいと思います。私はres
と呼ばれるリストでそれをキャプチャしました。オブジェクト(重要な場合)はstatsmodels
のMarkovRegressionResultsWrapper
オブジェクトです。Pythonでオブジェクトのリストを保存する
私は行く方法がピクルスだと思った。 JSONはオブジェクトのために機能しないようです(私は新しいので、おそらくこれは間違っていますか?)。
file_Name = "testfile"
# open the file for writing
fileObject = open(file_Name,'wb')
# this writes the object a to the
# file named 'testfile'
pickle.dump(res,fileObject)
# here we close the fileObject
fileObject.close()
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-43-ab4800ac1a51> in <module>()
7 # this writes the object a to the
8 # file named 'testfile'
----> 9 pickle.dump(res,fileObject)
10
11 # here we close the fileObject
OSError: [Errno 22] Invalid argument
I:私は正確に同じコードを使用しますが、私のリストの解像度を保存するとき、それはエラーになります、しかし
import pickle
a = ['test value','test value 2','test value 3']
file_Name = "testfile"
# open the file for writing
fileObject = open(file_Name,'wb')
# this writes the object a to the
# file named 'testfile'
pickle.dump(a,fileObject)
# here we close the fileObject
fileObject.close()
:ここ
が正常に動作します私が見つけた例です。 MacBook ProでJupyter NotebookでPython 3.6を使用しています。a
と
res
はどちらもリストタイプなので、リストとは唯一異なるものです。なぜこのエラーが発生するのですか?これは、オブジェクトのリストを保存するための最良の方法ですか、私は別の何かをしなければなりませんか?
あなたの 'pickle.dump'に' res'とは何ですか? – PYA
'res'は5,693のMarkovRegressionResultsWrapper'オブジェクトを含むリストです –
' OSError'は、ここで問題となるPythonコードであるとは限りませんが、これはシステムエラーメッセージです([doc](https:// docs .python.org/2/library/exceptions.html#exceptions.OSError))。あなたが書いているファイルの大きさはどれくらいですか? – patrick