XML, JSON, or what?
Frank Millman
frank at chagford.com
Sat Jun 17 02:23:52 EDT 2006
Daniel Dittmar wrote:
> > My client-server is Python-to-Python. At present, I am using cPickle to
> > transfer objects between the two. Among other things, I sometimes
> > transfer a tuple. Using JSON it appears on the other side as a list. As
> > I sometimes use the tuple as a dictionary key, this fails, as you
> > obviously cannot use a list as a key.
> [...]
> > Can someone confirm this, or is there an easy workaround?
>
> You can always convert a list to a tuple using the tuple () builtin
> right before you use it as a key. But you have to be sure that it is a
> list. tuple ("abc") => ('a', 'b', 'c') is probably not what you intend
> to do.
>
> Daniel
Thanks,Daniel. After sleeping on it, I had also come to the conclusion
that this is the easiest solution -
if isinstance(key,list):
key = tuple(key)
A bit of a kludge, but I can live with it. I will keep checking to see
if any other anomalies crop up.
Frank
More information about the Python-list
mailing list