Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > XML, JSON, or what?

Reply
Thread Tools

XML, JSON, or what?

 
 
Frank Millman
Guest
Posts: n/a
 
      06-17-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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments