Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #39701

Re: Good cross-version ASCII serialisation protocol for simple types

Newsgroups comp.lang.python
Date 2013-02-23 11:00 -0800
References <f1d3acb6-94e2-48f6-8ccd-042b929d0ef4@googlegroups.com> <qotwqtzf218.fsf@ruuvi.it.helsinki.fi>
Message-ID <37a63b6b-20f3-48b8-8ba7-b0475961ec2f@googlegroups.com> (permalink)
Subject Re: Good cross-version ASCII serialisation protocol for simple types
From Paul Moore <p.f.moore@gmail.com>

Show all headers | View raw


On Saturday, 23 February 2013 16:06:11 UTC, Jussi Piitulainen  wrote:
> I don't know much of these things but I've been using Python's
> json.dump and json.load for a couple of weeks now and they seem to use
> ASCII-friendly escapes automatically, writing a four-character string
> as "\u00e4\u00e4ni" instead of using the UTF-8 characters that my
> environment is set to handle.

Thanks. When I tried to write a short program to demo what I was doing, I realised that my problem was actually with my test code, not with json. Here's my test code:

import json, subprocess
CODE="""
import json
p = {'x': '\N{EURO SIGN}'}
print json.dumps(p)
"""
data_bytes = subprocess.check_output(['py', '-2', '-c', CODE])
data = json.loads(data_bytes.decode('ASCII'))
print(data)

The problem is that I'm not using a raw string for CODE, so the Euro sign is being put into the string literally, and that causes all sorts of encoding-related fun that I didn't intend!

As you say, json actually works fine for this application, so thanks for pointing that out. I thought it shouldn't need to be as hard as I was making it!!!

Paul.

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Good cross-version ASCII serialisation protocol for simple types Paul  Moore <p.f.moore@gmail.com> - 2013-02-23 07:45 -0800
  Re: Good cross-version ASCII serialisation protocol for simple types Chris Angelico <rosuav@gmail.com> - 2013-02-24 03:00 +1100
  Re: Good cross-version ASCII serialisation protocol for simple types Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2013-02-23 17:05 +0100
  Re: Good cross-version ASCII serialisation protocol for simple types Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2013-02-23 18:06 +0200
    Re: Good cross-version ASCII serialisation protocol for simple types Paul  Moore <p.f.moore@gmail.com> - 2013-02-23 11:00 -0800

csiph-web