[Python-ideas] Json object-level serializer

Antoine Pitrou solipsis at pitrou.net
Thu Jul 29 16:14:27 CEST 2010


Le jeudi 29 juillet 2010 à 16:03 +0200, Tarek Ziadé a écrit :
> On Thu, Jul 29, 2010 at 3:51 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> > Le jeudi 29 juillet 2010 à 15:47 +0200, Tarek Ziadé a écrit :
> >> On Thu, Jul 29, 2010 at 3:42 PM, Tarek Ziadé <ziade.tarek at gmail.com> wrote:
> >> >> And I don't see how `__json__` is more annoying than e.g. `to_json`.
> >>
> >> Its easier to override
> >
> > Could you expand a little bit?
> 
> If you want to override to_json in a subclass, to slightly adapt it, its easier
> because the __json__ name is mangled by Python

No, it isn't.

>>> class C:
...     def __json__(self):
...         pass
... 
>>> C.__json__
<function __json__ at 0x7f9cec489ea8>
>>> C().__json__
<bound method C.__json__ of <__main__.C object at 0x7f9cec482f90>>





More information about the Python-ideas mailing list