mirror of
https://github.com/python/cpython.git
synced 2025-11-13 23:46:24 +00:00
#9767: doctest run over json docs.
This commit is contained in:
parent
8d58216050
commit
0bb73b8be8
1 changed files with 5 additions and 5 deletions
|
|
@ -82,12 +82,12 @@ Extending :class:`JSONEncoder`::
|
||||||
... return [obj.real, obj.imag]
|
... return [obj.real, obj.imag]
|
||||||
... return json.JSONEncoder.default(self, obj)
|
... return json.JSONEncoder.default(self, obj)
|
||||||
...
|
...
|
||||||
>>> dumps(2 + 1j, cls=ComplexEncoder)
|
>>> json.dumps(2 + 1j, cls=ComplexEncoder)
|
||||||
'[2.0, 1.0]'
|
'[2.0, 1.0]'
|
||||||
>>> ComplexEncoder().encode(2 + 1j)
|
>>> ComplexEncoder().encode(2 + 1j)
|
||||||
'[2.0, 1.0]'
|
'[2.0, 1.0]'
|
||||||
>>> list(ComplexEncoder().iterencode(2 + 1j))
|
>>> list(ComplexEncoder().iterencode(2 + 1j))
|
||||||
['[', '2.0', ', ', '1.0', ']']
|
['[2.0', ', 1.0', ']']
|
||||||
|
|
||||||
|
|
||||||
.. highlight:: none
|
.. highlight:: none
|
||||||
|
|
@ -373,7 +373,7 @@ Encoders and decoders
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
return list(iterable)
|
return list(iterable)
|
||||||
return JSONEncoder.default(self, o)
|
return json.JSONEncoder.default(self, o)
|
||||||
|
|
||||||
|
|
||||||
.. method:: encode(o)
|
.. method:: encode(o)
|
||||||
|
|
@ -381,7 +381,7 @@ Encoders and decoders
|
||||||
Return a JSON string representation of a Python data structure, *o*. For
|
Return a JSON string representation of a Python data structure, *o*. For
|
||||||
example::
|
example::
|
||||||
|
|
||||||
>>> JSONEncoder().encode({"foo": ["bar", "baz"]})
|
>>> json.JSONEncoder().encode({"foo": ["bar", "baz"]})
|
||||||
'{"foo": ["bar", "baz"]}'
|
'{"foo": ["bar", "baz"]}'
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -390,5 +390,5 @@ Encoders and decoders
|
||||||
Encode the given object, *o*, and yield each string representation as
|
Encode the given object, *o*, and yield each string representation as
|
||||||
available. For example::
|
available. For example::
|
||||||
|
|
||||||
for chunk in JSONEncoder().iterencode(bigobject):
|
for chunk in json.JSONEncoder().iterencode(bigobject):
|
||||||
mysocket.write(chunk)
|
mysocket.write(chunk)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue