[Tutor] pickle in unicode format

BRINER Cedric work at infomaniak.ch
Thu Apr 7 09:34:30 CEST 2005


On Tue, 2005-04-05 at 11:33 -0700, Danny Yoo wrote:
> 
> > > I have this dictionnary :
> > >
> > > a={'partition': u'/export/diskH1/home_evol/ricquebo',
> > >  'rsmFirstname': u'Fran\xe7ois',
> > >  'rsmLastname': u'Ricquebourg',
> > >  'size': u'8161222.0',
> > >  'size_max': '1'}
> > >
> > > and I'd like to *serialize* it with pickle and that the output format
> > > will be of type unicode.
> >
> > I'm not sure what you mean by this. Do you mean that you want the actual
> > pickled data to be a unicode string? Or that you want to be able to
> > pickle something that contains unicode strings?
I mean that the pickled data to be an unicode string

> The first interpretation doesn't make sense to me either: pickled data is
> a 'byte' representation of your data structures.  Why do you need it to be
> treated as a unicode string?

because the idea is to have a database whom keeps email sent
automatically. And I've separated the canevas from the content. So in
the email table I have the column:
-'format' ----eg--> 'hello %(firstname)s %(lastname)s'
-'data'   ----eg--> where I'd like to put my dictionnary (e.g.
{'firstname':u'cedric','lastname':u'briner'}) 

but I cannot push to my database an python dictionnary. So I thought
that I can use pickle to push my dico.

I need the pickled data to be in unicode, because the program talk with
the database with unicode.

> > > unicode(pickle.dumps(a)) doesn't work !
> 
> Can you show us why this doesn't work for you?  I can guess why, but it is
> much better if we don't have to guess what the error message looks like.
> I suspect you're seeing something like this:
> 
> ######
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 0:
> ordinal not in range(128)
> ######
this is it!
> but again, I hate guessing.  *grin*
Sorry for this :(


> Show us exactly what you're seeing as an error message: don't just say it
> doesn't work, because that doesn't give us enough to know if the error or
> bug that we're seeing is the same one that you're seeing.  Problems often
> can have multiple causes, which is why we need to see the one you're
> getting stuck on.
got it, and yes I'll do it.


sorry to take so long to reply, but I get some problems with my emails.

Cedric BRINER



More information about the Tutor mailing list