[Tutor] dictionary2unicode and unicode2dictionnary

BRINER Cedric work at infomaniak.ch
Fri Apr 8 13:29:16 CEST 2005


hi,

sorry to relaunch this topie but I really need this to work. (o.o)'

how can I have an unicode pickled data ???

e.g.

a={'partition': u'/export/diskH1/home_evol/ricquebo',
'rsmFirstname': u'Fran\xe7ois',
'rsmLastname': u'Ricquebourg',
'size': u'8161222.0',
'size_max': '1'}

<(hint: rsmFirstname = françois)>

import pickle

q=pickle.dumps(a)
>>> type(q)
<type 'str'>
so this is a string

>>> unicode(q)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe7 in position 64:
ordinal not in range(128)

at position 64
>>> q[:64]
"(dp0\nS'rsmLastname'\np1\nVRicquebourg\np2\nsS'rsmFirstname'\np3
\nVFran"
there is the ç : it's the a special 'c'

In fact, what I really need is the ability to push a dictionary (which
can contain unicode) in a postgres database.

and the sql command given are in unicode. Thus I need to transform a
dictionnary--to-->unicode and then, do the inverse operation
unicode--to-->dictionnary


Cedric BRINER



More information about the Tutor mailing list