Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #4579

Re: Pickling extension types

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'attribute': 0.09; "module's": 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'underlying': 0.09; 'pm,': 0.11; 'extension': 0.14; 'wrote:': 0.14; 'enigma': 0.16; 'kern': 0.16; 'lookup': 0.16; 'namespace.': 0.16; 'py_none,': 0.16; 'received:216.62': 0.16; 'received:216.62.213': 0.16; 'received:enthought.com': 0.16; '16,': 0.16; 'traceback': 0.16; '(most': 0.16; 'interpret': 0.19; 'header:In-Reply-To:1': 0.22; 'trying': 0.23; 'last):': 0.23; 'modification': 0.23; 'skip:- 70': 0.24; 'object': 0.27; 'thanks': 0.29; 'error': 0.29; 'stefan': 0.29; 'skip:( 20': 0.31; "can't": 0.31; 'to:addr:python-list': 0.32; '...': 0.32; 'url:docs': 0.33; 'test': 0.33; 'header:X-Complaints-To:1': 0.34; 'skip:" 10': 0.34; 'file': 0.35; 'print': 0.35; 'header:User-Agent:1': 0.35; 'module.': 0.35; 'two': 0.37; 'url:python': 0.37; 'url:org': 0.38; 'received:org': 0.38; 'though': 0.38; 'set': 0.39; 'to:addr:python.org': 0.39; 'where': 0.39; 'header:Mime- Version:1': 0.39; 'add': 0.39; 'attempt': 0.40; 'header:Received:5': 0.40; 'our': 0.63; 'world': 0.65; 'believe': 0.66; 'eco': 0.84; 'subject:types': 0.84; 'things:': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Robert Kern <robert.kern@gmail.com>
Subject Re: Pickling extension types
Date Tue, 03 May 2011 17:05:23 -0500
Organization The Church of Last Thursday
References <BANLkTi=sUu_VFKrW+KSk8-RDzr5vgSLKqQ@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host outbound.enthought.com
User-Agent Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9
In-Reply-To <BANLkTi=sUu_VFKrW+KSk8-RDzr5vgSLKqQ@mail.gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1126.1304460339.9059.python-list@python.org> (permalink)
Lines 40
NNTP-Posting-Host 82.94.164.166
X-Trace 1304460339 news.xs4all.nl 41117 [::ffff:82.94.164.166]:49670
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:4579

Show key headers only | View raw


On 5/3/11 4:34 PM, Stefan Kuzminski wrote:
> Thanks for the clues, I made a modification so that reduce returns this..
>
>    return Py_BuildValue("O(OOOOO)", Py_TYPE(self), PyTuple_New(0), Py_None,
> Py_None, Py_None );
>
> and now I get this different error when trying to pickle the type..
>
>   ----------------------------------------------------------------------
> Traceback (most recent call last):
>    File "test_missing.py", line 16, in test
>      print cPickle.dumps( mv )
> PicklingError: Can't pickle <type 'MV'>: attribute lookup __builtin__.MV failed

You need to do two things:

1. Set tp_name to something like "mymodule.MV" where "mymodule" is the name of 
your extension module.

2. Make sure that you add the type object to your module's namespace.

PyMODINIT_FUNC
initmymodule(void) {
   ...
   Py_INCREF(&PyMV_Type);
   PyModule_AddObject(m, "MV", (PyObject*)&PyMV_Type);
}

C.f.

http://docs.python.org/extending/newtypes.html

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Pickling extension types Robert Kern <robert.kern@gmail.com> - 2011-05-03 17:05 -0500

csiph-web