Skip to main content

All Questions

Tagged with
0 votes
1 answer
126 views

_pickle.PicklingError: Can't pickle <class '__main___.{CONST} '>: attribute lookupfaileddir_namesmain_on __main__ failed

firstly dir_names works well when pickling dir_names = collections.namedtuple('dir_names', ['mark', 'category']) pickle.dump(dir_names, open('tmp.bin', 'wb')) I want make dir_name a const DIR_NAMES = ...
king Carrey's user avatar
0 votes
2 answers
234 views

Are pickle-able tuple-factories (with names) possible?

There are several questions about pickling namedtuples already, however none of the ones I found [1] [2] [3] [4] deals with the case of pickling a namedtuple that is bound on an object instance. ...
Hyperplane's user avatar
  • 1,644
0 votes
1 answer
115 views

Pickle doesn't work for class inherited from "namedtuple" when overriding "__new__"

The following code fails from collections import namedtuple import pickle class Foo(namedtuple("_Foo", ["a", "b"])): def __new__(cls, **kwargs): self = super().__new__(cls, **kwargs) ...
knub's user avatar
  • 4,022
2 votes
1 answer
216 views

How to pickle namedtuple subclass with RSAPublicKey field

I'm trying to serialize objects that subclass namedtuple and hold references to RSAPublicKey objects. I subclass a namedtuple to create immutable object instances. One of the fields of my class holds ...
leiter_jakab's user avatar
1 vote
1 answer
2k views

Pickle can't pickle a namedtuple

I am trying to pickle the namedtuple like this: def f(): TemplateData = namedtuple('TemplateData', ['field1', 'field2']) f1 = np.random.randn(50,50) f2 = np.random.randn(50,50) td = ...
Ladenkov Vladislav's user avatar
2 votes
2 answers
526 views

Space-efficient pickling of Cython objects in Python?

I'm trying to find a space-efficient way to store a struct-like object in Python. # file point.py import collections Point = collections.namedtuple('Point', ['x', 'y']) Here's the cythonized ...
Katie's user avatar
  • 958
5 votes
2 answers
3k views

Adding extra fields to an existing namedtuple object and unpickling

I have some data in the pickled format with instances of below objects: Point = namedtuple('Point', ['x',]) Now I want to extend the Point object to add another variable 'y' but also keep this ...
Mohit's user avatar
  • 51
0 votes
1 answer
643 views

Python dill: Pickle namedtuple doesnt seem to work

I have namedtuple inside a class. When pickling using dill, it complains the classic issue of not being able to find the namedtuple object at top module. import dill as pickle class NNRTMParse(...
rrkarts's user avatar
  • 11
9 votes
1 answer
4k views

Where should I define namedtuple classes in Python - which namespace?

Namedtuples are useful in Python to name small collections of data. Take for example this namedtuple: import collections sesameEpisodeNTC = collections.namedtuple('sesameEpisodeNTC', ...
MHH's user avatar
  • 363
1 vote
1 answer
710 views

How can I use my 'namedtuple' structure with 'pickle'? [duplicate]

I have created tuple of dictionary using from collections import namedtuple import random demand={} Site_Product=namedtuple("Site_Product", ["site", "product"]) Products=['P1','P2','P3'] ...
Ozgu's user avatar
  • 133
12 votes
1 answer
2k views

Why can't I pickle a typing.NamedTuple while I can pickle a collections.namedtuple?

Why can't I pickle a typing.NamedTuple while I can pickle a collections.namedtuple? How can I manage to do pickle a NamedTuple? This code shows what I have tried so far: from collections import ...
marcotama's user avatar
  • 2,053
0 votes
1 answer
328 views

namedtuple pickling fails when variable name doesn't match typename

The python code below fails with the error pickle.PicklingError: Can't pickle <class '__main__.SpecialName'>: it's not found as __main__.SpecialName import pickle from collections import ...
eqzx's user avatar
  • 5,477
9 votes
3 answers
10k views

Writing and reading namedtuple into a file in python

I need to write a data structure stored as namedtuple to file and read it back as a namedtuple in python. Solutions here suggest using Json.load/loads or pickle which write the variable as json key-...
amitp's user avatar
  • 91
7 votes
2 answers
4k views

Multiprocessing objects with namedtuple - Pickling Error

I am having trouble using namedtuples in objects that I want to put into multiprocessing. I am receiving pickling error. I tried couple of things from other stackoverflow posts, but I could not ...
Enes's user avatar
  • 189
6 votes
1 answer
2k views

Understanding an issue with the namedtuple typename and pickle in Python

Earlier today I was having trouble trying to pickle a namedtuple instance. As a sanity check, I tried running some code that was posted in another answer. Here it is, simplified a little more: from ...
YXD's user avatar
  • 32.3k

15 30 50 per page