Pickle problem

Michael Stenner mstenner at phy.duke.edu
Tue Sep 10 08:59:28 EDT 2002


On Tue, Sep 10, 2002 at 01:44:57PM +0100, Harvey Thomas wrote:
> Erik Price wrote:
> > 
> > On Tuesday, September 10, 2002, at 06:13  AM, Harvey Thomas wrote:
> > 
> > > I'm trying to pickle a complicated data structure which includes a 
> > > dictionary whose entries are created by (simplified):
> > >
> > > a[x] = re.compile(y).match
> > >
> > > The pickle fails, however, with the error:
> > >
> > > PicklingError: Can't pickle <built-in method match of 
> > _sre.SRE_Pattern 
> > > object at
> > >  0x00838700>: it's not found as __main__.match
> > >
> > > I'd be grateful if someone could tell me if it is possible 
> > to pickle 
> > > the data structure and what I'm doing wrongly.
> > 
> > Are you trying to store the MatchObject returned by a call to 
> > a regular 
> > expression object's match() method?  If so, it looks like you're 
> > forgetting the parens at the end of "re.compile(y).match".
> > 
> No, I haven't forgotten the parentheses. I'd like to pickle the match method of the compiled regular expression.

My bad... I just reread this.  I had misread it before.  Sorry for the
misunderstanding.  I am bit curious about what you get out of pickling
the method that you can't get from the compiled re object itself.
You can always call the match method after unpickling, right?

-- 
  Michael Stenner                       Office Phone: 919-660-2513
  Duke University, Dept. of Physics       mstenner at phy.duke.edu
  Box 90305, Durham N.C. 27708-0305




More information about the Python-list mailing list