pickle

More on python ImportError No module named

坚强是说给别人听的谎言 提交于 2019-12-05 21:28:42
Following the suggestion here , my package (or the directory containing my modules) is located at C:/Python34/Lib/site-packages. The directory contains an __init__.py and sys.path contains a path to the directory as shown. Still I am getting the following error: Traceback (most recent call last): File "C:/Python34/Lib/site-packages/toolkit/window.py", line 6, in <module> from catalogmaker import Catalog File "C:\Python34\Lib\site-packages\toolkit\catalogmaker.py", line 1, in <module> from patronmaker import Patron File "C:\Python34\Lib\site-packages\toolkit\patronmaker.py", line 4, in <module>

XML object serialization in python, are there any alternatives to Gnosis?

做~自己de王妃 提交于 2019-12-05 18:13:35
For a while I've been using a package called "gnosis-utils" which provides an XML pickling service for Python. This class works reasonably well, however it seems to have been neglected by it's developer for the last four years. At the time we originally selected gnosis it was the only XML serization tool for Python. The advantage of Gnosis was that it provided a set of classes whose function was very similar to the built-in Python XML pickler. It produced XML which python-developers found easy to read, but non-python developers found confusing. Now that the proejct has grown we have a new

Serializing an object in __main__ with pickle or dill

柔情痞子 提交于 2019-12-05 18:13:11
I have a pickling problem. I want to serialize a function in my main script, then load it and run it in another script. To demonstrate this, I've made 2 scripts: Attempt 1: The naive way: dill_pickle_script_1.py import pickle import time def my_func(a, b): time.sleep(0.1) # The purpose of this will become evident at the end return a+b if __name__ == '__main__': with open('testfile.pkl', 'wb') as f: pickle.dump(my_func, f) dill_pickle_script_2.py import pickle if __name__ == '__main__': with open('testfile.pkl') as f: func = pickle.load(f) assert func(1, 2)==3 Problem : when I run script 2, I

Custom sklearn pipeline transformer giving “pickle.PicklingError”

拟墨画扇 提交于 2019-12-05 18:11:14
I am trying to create a custom transformer for a Python sklearn pipeline based on guidance from this tutorial: http://danielhnyk.cz/creating-your-own-estimator-scikit-learn/ Right now my custom class/transformer looks like this: class SelectBestPercFeats(BaseEstimator, TransformerMixin): def __init__(self, model=RandomForestRegressor(), percent=0.8, random_state=52): self.model = model self.percent = percent self.random_state = random_state def fit(self, X, y, **fit_params): """ Find features with best predictive power for the model, and have cumulative importance value less than self.percent

how to make classes with __getattr__ pickable

馋奶兔 提交于 2019-12-05 17:20:46
How can I modify the classes below to make them pickeable? This question: How to make a class which has __getattr__ properly pickable? is similar but refer to wrong exception in the use of getattr . This other question seems to provide meaningful insight Why does pickle.dumps call __getattr__? , however it fails to provide an example, and I honestly cannot understand what I am suppose to implement. import pickle class Foo(object): def __init__(self, dct): for key in dct: setattr(self, key, dct[key]) class Bar(object): def __init__(self, dct): for key in dct: setattr(self, key, dct[key]) def _

pickle.dump meet RuntimeError: maximum recursion depth exceeded in cmp

旧街凉风 提交于 2019-12-05 15:57:43
I have noticed that it may be caused by beautifulsoup or recursive data structure. however, the data structure that cause error seems no problem: class Movie: def __init__(self, name="", dscore=0, mscore=0, durl="", murl=""): self.name = name self.dscore = float(dscore) self.mscore = float(mscore) self.durl = durl self.murl = murl def __str__(self): return unicode(self.name) + u' / ' + unicode(self.dscore) + u' / ' + unicode(self.mscore) \ + u' / ' + unicode(self.durl) + u' / ' + unicode(self.murl) The statement causing the problem is: DataDict['MovieInfo'] = MovieInfo and pickle.dump(DataDict

Pickle cross platform __dict__ attribute error

左心房为你撑大大i 提交于 2019-12-05 15:07:25
I'm having an issue with pickle. Things work fine between OSX and Linux, but not Windows and Linux. All pickled strings are stored in memory and sent via an SSL socket. To be 100% clear I have replaced all '\n's with ":::" and all '\r's with "===" (there were none). Scenario: Client-Win: Small Business Server 2011 running Python 2.7 Client-Lin: Fedora Linux running Python 2.7 Server: Fedora Linux running Python 2.7 Client-Lin sends a pickled object to Server: ccopy_reg:::_reconstructor:::p0:::(c__main__:::infoCollection:::p1:::c__builtin__:::tuple:::p2:::(VSTRINGA:::p3:::VSTRINGB:::p4::

Pickling a Spark RDD and reading it into Python

↘锁芯ラ 提交于 2019-12-05 14:20:29
I am trying to serialize a Spark RDD by pickling it, and read the pickled file directly into Python. a = sc.parallelize(['1','2','3','4','5']) a.saveAsPickleFile('test_pkl') I then copy the test_pkl files to my local. How can I read them directly into Python? When I try the normal pickle package, it fails when I attempt to read the first pickle part of 'test_pkl': pickle.load(open('part-00000','rb')) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib64/python2.6/pickle.py", line 1370, in load return Unpickler(file).load() File "/usr/lib64/python2.6/pickle.py"

Python dictionary loaded from disk takes too much space in memory

回眸只為那壹抹淺笑 提交于 2019-12-05 13:45:47
I have a dictionary pickled on disk with size of ~780 Megs (on disk). However, when I load that dictionary into the memory, its size swells unexpectedly to around 6 gigabytes. Is there anyway to keep the size around the actual filesize in the memory as well, (I mean it will be alright if it takes around 1 gigs in the memory, but 6 gigs is kind of a strange behavior). Is there a problem with the pickle module, or should I save the dictionary in some other format? Here is how I am loading the file: import pickle with open('py_dict.pickle', 'rb') as file: py_dict = pickle.load(file) Any ideas,

Why can't I pickle an error's Traceback in Python?

天大地大妈咪最大 提交于 2019-12-05 11:52:53
问题 I've since found a work around, but still want to know the answer. 回答1: The traceback holds references to the stack frames of each function/method that was called on the current thread, from the topmost-frame on down to the point where the error was raised. Each stack frame also holds references to the local and global variables in effect at the time each function in the stack was called. Since there is no way for pickle to know what to serialize and what to ignore, if you were able to pickle