Save and load initialized class

Bob van der Poel bob at mellowood.ca
Sun Dec 10 19:19:26 EST 2017


Yes, all cool. But,

   json.dump(Opts.__dict__, open("mybuffer", "w"))

still doesn't work with python3. Returns "is not JSON serializable"

On Sun, Dec 10, 2017 at 4:00 AM, Steve D'Aprano <steve+python at pearwood.info>
wrote:

> On Sun, 10 Dec 2017 04:52 am, MRAB wrote:
>
> > Try updating __dict__:
> >
> >      Opts.__dict__.update(json.load(open("mybuffer")))
>
> __dict__ is implementation, vars() is the public interface:
>
> vars(Opts).update(json.load(open("mybuffer")))
>
>
> Looks nicer too :-)
>
>
>
>
> --
> Steve
> “Cheer up,” they said, “things could be worse.” So I cheered up, and sure
> enough, things got worse.
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 

**** Listen to my FREE CD at http://www.mellowood.ca/music/cedars ****
Bob van der Poel ** Wynndel, British Columbia, CANADA **
EMAIL: bob at mellowood.ca
WWW:   http://www.mellowood.ca



More information about the Python-list mailing list