pickle

Why my code doesn't save/load my data in python?

自闭症网瘾萝莉.ら 提交于 2019-12-13 17:25:25
问题 I use the following code(you can copy and run the code, it works) to load(if exists) and save the data to reuse it in the next execution of my program, but it doesn't work: import matplotlib.pyplot as plt import time import requests import pickle z = [] try: with open('3_tir.pickle', 'rb') as f: last_prices = pickle.load(f) print("pickle loaded") #f = open("last_prices.txt", 'a+') #f.read() except Exception: #f = open("last_prices.txt", 'a+') pass for i in range(25200): time.sleep(1) with

Python Multiprocessing: AttributeError: 'Test' object has no attribute 'get_type'

元气小坏坏 提交于 2019-12-13 13:55:07
问题 short short version: I am having trouble parallelizing code which uses instance methods. Longer version: This python code produces the error: Error Traceback (most recent call last): File "/Users/gilzellner/dev/git/3.2.1-build/cloudify-system-tests/cosmo_tester/test_suites/stress_test_openstack/test_file.py", line 24, in test self.pool.map(self.f, [self, url]) File "/Users/gilzellner/.virtualenvs/3.2.1-build/lib/python2.7/site-packages/pathos/multiprocessing.py", line 131, in map return _pool

Python: pickle.loads failed for class instance

寵の児 提交于 2019-12-13 13:54:13
问题 I need tzinfo class for datetime object in my class. I need to pickle my class. But pickle.loads(obj) failed. What's wrong with mytz class? If I do not use mytz class everything works. Why? from datetime import datetime, tzinfo, timedelta # Timezone class class mytz (tzinfo): def __init__(self, offset, dst): self._tzname = offset + ' ' + dst self._offset = timedelta(hours=int(offset[0:3]), minutes=int(offset[0:1]+offset[3:])) self._dst = timedelta(hours=int(dst[0:3]), minutes=int(dst[0:1]+dst

Pickles: Why are they called that? [closed]

北慕城南 提交于 2019-12-13 12:53:21
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . I'm surprised this is such a hard answer for me to find. It's such a strange name. Why are pickles called pickles? http://en.wikipedia.org/wiki/Pickle_(Python) I understand what "pickling" means with respect to vegetables and I understand that the python concept is analogous.

How to store a big dictionary?

北城以北 提交于 2019-12-13 11:36:58
问题 I have a big dictionary(28 MB) 'MyDict' stored in a MyDict.py file. If I execute the statement: from MyDict import MyDict A MemoryError exception is thrown. How can I access this dictionary using cPickle or shelve modules. How can I write this MyDict.py file to cPickle or shelve without accessing MyDict. This MyDict is generated by writing into a file. Here is a key-value pair from the dictionary: {"""ABCD""" : [[(u'2011-03-21', 35.5, 37.5, 35.3, 35.85, 10434.0, 35.85), (u'2012-03-03', 86.0,

Pickle user inputs - Python 3 [closed]

孤街浪徒 提交于 2019-12-13 11:20:48
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I am pretty desperate, since I have tried to get this working in a long time. I'm making a text adventure where some user inputs choose the player's hp, dmg, you name it. I want to make a save function, but every time I load it, the player has default parameters. Example: class player: def __init__(self, hp, dmg

Unable to load pickle object from file

社会主义新天地 提交于 2019-12-13 10:24:56
问题 I'm just trying out the pickle module and learning its functions and utilities. I've written this small piece of code, but it's giving me trouble. import pickle myfile = open("C:\\Users\\The Folder\\databin.txt", 'r+') #databin.txt is completely blank class A: def __init__ (self): self.variable = 25 self.random = 55 pickle.dump (A, myfile, -1) #HIGHEST_PROTOCOL pickle.load (myfile) I then get the following error: Traceback (most recent call last): File "<pyshell#9>", line 1, in <module>

Python 3.6 pickling custom procedure

帅比萌擦擦* 提交于 2019-12-13 09:28:11
问题 I have some objects of class A which has its own method to be pickled, call it custom_module.customPickle(A) which takes an instance of A and returns a serialization string. I also have list of objects each of class B that contains A . I need to pickle the list, but pickling A gives some error difficult to solve. However, A has its own method to be pickled. I can implement the __reduce__() method in class B so that it calls custom_module.customPickle(A) . But how can I do this so that pickle

dill dump_session with ipython

随声附和 提交于 2019-12-13 02:22:22
问题 I'm trying to use the dill module to save my ipython session using dump_session() but I'm getting an error message. I'm using Ipython 1.0.0 and dill 0.2-a-dev 20120503. Does anyone out there have any insight? Thanks in advance. Niall Here's the enormous traceback: --------------------------------------------------------------------------- AssertionError Traceback (most recent call last) <ipython-input-15-9934c16a537e> in <module>() ----> 1 dill.dump_session("/data/local/nrobin/tset.sess")

Multiprocessing: Pool and pickle Error — Pickling Error: Can't pickle <type 'instancemethod'>: attribute lookup __builtin__.instancemethod failed

荒凉一梦 提交于 2019-12-13 02:04:09
问题 I have two files: x.py class BF(object) def __init__(): . . def add(self,z): . . y.py from y import BF def FUNC((a,b,bf)) . . bf.add(x) . . return bf . . if __name__ == '__main__': pool = multiprocessing.Pool(3) for i in range(len(sl)): bf_set.append(BF()) results = pool.map(FUNC,zip(sl, itertools.repeat(aa), bf_set)) I also tried to define BF inside FUNC, but sill I got: PicklingError: Can't pickle <type 'instancemethod'>: attribute lookup __builtin__.instancemethod failed I've read some