Re: Storing instances using jsonpickle

2014-09-15 Thread Josh English
On Wednesday, September 3, 2014 7:19:07 PM UTC-7, Ned Batchelder wrote: > Typically, you need to decide explicitly on a serialized representation > for your data. Even if it's JSON, you need to decide what that JSON > looks like. Then you need to write code that converts the JSON-able > data

Re: Storing instances using jsonpickle

2014-09-06 Thread Terry Reedy
On 9/6/2014 12:32 PM, MRAB wrote: On 2014-09-06 01:20, Chris Angelico wrote: On Sat, Sep 6, 2014 at 3:04 AM, MRAB wrote: JSON has 'true' and 'false'. Python has 'True' and 'False'. Therefore, if you want it to be able to drop it into Python's REPL, it won't be compatible with JSON anyway! (W

Re: Storing instances using jsonpickle

2014-09-06 Thread Ned Batchelder
On 9/6/14 12:32 PM, MRAB wrote: On 2014-09-06 01:20, Chris Angelico wrote: On Sat, Sep 6, 2014 at 3:04 AM, MRAB wrote: JSON has 'true' and 'false'. Python has 'True' and 'False'. Therefore, if you want it to be able to drop it into Python's REPL, it won't be compatible with JSON anyway! (Wel

Re: Storing instances using jsonpickle

2014-09-06 Thread MRAB
On 2014-09-06 01:20, Chris Angelico wrote: On Sat, Sep 6, 2014 at 3:04 AM, MRAB wrote: JSON has 'true' and 'false'. Python has 'True' and 'False'. Therefore, if you want it to be able to drop it into Python's REPL, it won't be compatible with JSON anyway! (Well, not unless you define 'true' a

Re: Storing instances using jsonpickle

2014-09-05 Thread Chris Angelico
On Sat, Sep 6, 2014 at 3:04 AM, MRAB wrote: > JSON has 'true' and 'false'. > > Python has 'True' and 'False'. > > Therefore, if you want it to be able to drop it into Python's REPL, it > won't be compatible with JSON anyway! (Well, not unless you define > 'true' and 'false' first.) This is a new

Re: Storing instances using jsonpickle

2014-09-05 Thread Irmen de Jong
On 5-9-2014 19:16, Marko Rauhamaa wrote: > Thus, ast.literal_eval() is superior to anything JSON has to offer. Incidentally, I've made a serialization library based on Python's literal expressions. It uses ast.literal_eval() to deserialize, and a bit of custom code to serialize Python objects:

Re: Storing instances using jsonpickle

2014-09-05 Thread Marko Rauhamaa
Ned Batchelder : > I see what you mean about JSON, but you are mistaken about HTTP and > XML. Neither of them dictates the encoding of the data, and both of > them offer ways to declare the encoding. This means XML parsers must > be prepared for many different encodings. You can rest assured that

Re: Storing instances using jsonpickle

2014-09-05 Thread Ned Batchelder
On 9/5/14 2:04 PM, Marko Rauhamaa wrote: Ned Batchelder : I don't understand how JSON has flopped? The parser may be a bit more complex (but not much, it isn't hard to examine the first few bytes), but you're using off-the-shelf parsers anyway, so why are you concerned by this? There are occa

Re: Storing instances using jsonpickle

2014-09-05 Thread Marko Rauhamaa
Ned Batchelder : > I don't understand how JSON has flopped? The parser may be a bit more > complex (but not much, it isn't hard to examine the first few bytes), > but you're using off-the-shelf parsers anyway, so why are you > concerned by this? There are occasions where you need to take shortcut

Re: Storing instances using jsonpickle

2014-09-05 Thread Ned Batchelder
On 9/5/14 1:16 PM, Marko Rauhamaa wrote: MRAB : Therefore, if you want it to be able to drop it into Python's REPL, it won't be compatible with JSON anyway! (Well, not unless you define 'true' and 'false' first.) Sigh. I was so hopeful JSON would be great. Unfortunately, it flopped by requiri

Re: Storing instances using jsonpickle

2014-09-05 Thread Marko Rauhamaa
MRAB : > Therefore, if you want it to be able to drop it into Python's REPL, it > won't be compatible with JSON anyway! (Well, not unless you define > 'true' and 'false' first.) Sigh. I was so hopeful JSON would be great. Unfortunately, it flopped by requiring the parser to heuristically support

Re: Storing instances using jsonpickle

2014-09-05 Thread MRAB
On 2014-09-04 06:17, Chris Angelico wrote: On Thu, Sep 4, 2014 at 9:39 AM, MRAB wrote: I occasionally think about a superset of JSON, called, say, "pyson" ... ah, name already taken! :-( While I'm somewhat sympathetic to the concept, there are some parts of your description that I disagree wi

Re: Storing instances using jsonpickle

2014-09-04 Thread Chris Angelico
On Fri, Sep 5, 2014 at 2:38 PM, Dan Sommers wrote: > On Thu, 04 Sep 2014 15:17:17 +1000, Chris Angelico wrote: > >> On Thu, Sep 4, 2014 at 9:39 AM, MRAB wrote: > >>> The key of a dict could also be int, float, or tuple. >> >> Yes! Yes! DEFINITELY do this!! Ahem. Calm down a little, it's not that

Re: Storing instances using jsonpickle

2014-09-04 Thread Dan Sommers
On Thu, 04 Sep 2014 15:17:17 +1000, Chris Angelico wrote: > On Thu, Sep 4, 2014 at 9:39 AM, MRAB wrote: >> The key of a dict could also be int, float, or tuple. > > Yes! Yes! DEFINITELY do this!! Ahem. Calm down a little, it's not that > outlandish an idea... Using floats is a bad idea. Consi

Re: Storing instances using jsonpickle

2014-09-04 Thread MRAB
On 2014-09-04 06:17, Chris Angelico wrote:> On Thu, Sep 4, 2014 at 9:39 AM, MRAB wrote: >> I occasionally think about a superset of JSON, called, say, "pyson" >> ... ah, name already taken! :-( > > While I'm somewhat sympathetic to the concept, there are some parts > of your description that I di

Re: Storing instances using jsonpickle

2014-09-03 Thread Chris Angelico
On Thu, Sep 4, 2014 at 9:39 AM, MRAB wrote: > I occasionally think about a superset of JSON, called, say, "pyson" ... > ah, name already taken! :-( While I'm somewhat sympathetic to the concept, there are some parts of your description that I disagree with. Am I misreading something? Are there ty

Re: Storing instances using jsonpickle

2014-09-03 Thread Sam Raker
1) There are, if you want to mess around with them, ways to make pickle "smarter" about class stuff: https://docs.python.org/2/library/pickle.html#pickling-and-unpickling-normal-class-instances . I've never worked with any of this stuff (and people don't seem to like pickle all that much), and

Re: Storing instances using jsonpickle

2014-09-03 Thread Ned Batchelder
On 9/3/14 6:30 PM, Josh English wrote: On Wednesday, September 3, 2014 1:53:23 PM UTC-7, Ned Batchelder wrote: Pickle (and it looks like jsonpickle) does not invoke the class' __init__ method when it reconstitutes objects. Your new __init__ is not being run, so new attributes it defines are no

Re: Storing instances using jsonpickle

2014-09-03 Thread Denis McMahon
On Thu, 04 Sep 2014 00:39:07 +0100, MRAB wrote: > It would add tuples, delimited by (...), which are not used otherwise > (no expressions): I guess <> and () are both unused as delims by json at present. I like the idea of other key types than string. -- Denis McMahon, denismfmcma...@gmail.com

Re: Storing instances using jsonpickle

2014-09-03 Thread MRAB
On 2014-09-03 23:30, Josh English wrote: On Wednesday, September 3, 2014 1:53:23 PM UTC-7, Ned Batchelder wrote: Pickle (and it looks like jsonpickle) does not invoke the class' __init__ method when it reconstitutes objects. Your new __init__ is not being run, so new attributes it defines are

Re: Storing instances using jsonpickle

2014-09-03 Thread Josh English
On Wednesday, September 3, 2014 1:53:23 PM UTC-7, Ned Batchelder wrote: > Pickle (and it looks like jsonpickle) does not invoke the class' > __init__ method when it reconstitutes objects. Your new __init__ is not > being run, so new attributes it defines are not being created. > > This is one o

Re: Storing instances using jsonpickle

2014-09-03 Thread Ned Batchelder
On 9/3/14 4:32 PM, Josh English wrote: I am using jsonpickle to store instances of an object into separate data files. If I make any changes to the original class definition of the object, when I recreate my stored instances, they are recreated using the original class definition, so any new a