source stringclasses 1 value | version stringclasses 1 value | module stringclasses 43 values | function stringclasses 307 values | input stringlengths 3 496 | expected stringlengths 0 40.5k | signature stringclasses 0 values |
|---|---|---|---|---|---|---|
cpython | cfcd524 | json | __module__ | >>> import json | null | |
cpython | cfcd524 | json | __module__ | >>> json.dumps(['foo', {'bar': ('baz', None, 1.0, 2)}]) | '["foo", {"bar": ["baz", null, 1.0, 2]}]' | null |
cpython | cfcd524 | json | __module__ | >>> print(json.dumps("\"foo\bar")) | "\"foo\bar" | null |
cpython | cfcd524 | json | __module__ | >>> print(json.dumps('\u1234')) | "\u1234" | null |
cpython | cfcd524 | json | __module__ | >>> print(json.dumps('\\')) | "\\" | null |
cpython | cfcd524 | json | __module__ | >>> print(json.dumps({"c": 0, "b": 0, "a": 0}, sort_keys=True)) | {"a": 0, "b": 0, "c": 0} | null |
cpython | cfcd524 | json | __module__ | >>> from io import StringIO | null | |
cpython | cfcd524 | json | __module__ | >>> io = StringIO() | null | |
cpython | cfcd524 | json | __module__ | >>> json.dump(['streaming API'], io) | null | |
cpython | cfcd524 | json | __module__ | >>> io.getvalue() | '["streaming API"]'
Compact encoding:: | null |
cpython | cfcd524 | json | __module__ | >>> import json | null | |
cpython | cfcd524 | json | __module__ | >>> mydict = {'4': 5, '6': 7} | null | |
cpython | cfcd524 | json | __module__ | >>> json.dumps([1,2,3,mydict], separators=(',', ':')) | '[1,2,3,{"4":5,"6":7}]'
Pretty printing:: | null |
cpython | cfcd524 | json | __module__ | >>> import json | null | |
cpython | cfcd524 | json | __module__ | >>> print(json.dumps({'4': 5, '6': 7}, sort_keys=True, indent=4)) | {
"4": 5,
"6": 7
}
Decoding JSON:: | null |
cpython | cfcd524 | json | __module__ | >>> import json | null | |
cpython | cfcd524 | json | __module__ | >>> obj = ['foo', {'bar': ['baz', None, 1.0, 2]}] | null | |
cpython | cfcd524 | json | __module__ | >>> json.loads('["foo", {"bar":["baz", null, 1.0, 2]}]') == obj | True | null |
cpython | cfcd524 | json | __module__ | >>> json.loads('"\\"foo\\bar"') == '"foo\x08ar' | True | null |
cpython | cfcd524 | json | __module__ | >>> from io import StringIO | null | |
cpython | cfcd524 | json | __module__ | >>> io = StringIO('["streaming API"]') | null | |
cpython | cfcd524 | json | __module__ | >>> json.load(io)[0] == 'streaming API' | True
Specializing JSON object decoding:: | null |
cpython | cfcd524 | json | __module__ | >>> import json | null | |
cpython | cfcd524 | json | __module__ | >>> def as_complex(dct):
... if '__complex__' in dct:
... return complex(dct['real'], dct['imag'])
... return dct
... | null | |
cpython | cfcd524 | json | __module__ | >>> json.loads('{"__complex__": true, "real": 1, "imag": 2}',
... object_hook=as_complex) | (1+2j) | null |
cpython | cfcd524 | json | __module__ | >>> from decimal import Decimal | null | |
cpython | cfcd524 | json | __module__ | >>> json.loads('1.1', parse_float=Decimal) == Decimal('1.1') | True
Specializing JSON object encoding:: | null |
cpython | cfcd524 | json | __module__ | >>> import json | null | |
cpython | cfcd524 | json | __module__ | >>> def encode_complex(obj):
... if isinstance(obj, complex):
... return [obj.real, obj.imag]
... raise TypeError(f'Object of type {obj.__class__.__name__} '
... f'is not JSON serializable')
... | null | |
cpython | cfcd524 | json | __module__ | >>> json.dumps(2 + 1j, default=encode_complex) | '[2.0, 1.0]' | null |
cpython | cfcd524 | json | __module__ | >>> json.JSONEncoder(default=encode_complex).encode(2 + 1j) | '[2.0, 1.0]' | null |
cpython | cfcd524 | json | __module__ | >>> ''.join(json.JSONEncoder(default=encode_complex).iterencode(2 + 1j)) | '[2.0, 1.0]'
Using json from the shell to validate and pretty-print::
$ echo '{"json":"obj"}' | python -m json
{
"json": "obj"
}
$ echo '{ 1.2:3.4}' | python -m json
Expecting property name enclosed in double quotes: line 1 column 3 (char 2) | null |
cpython | cfcd524 | json.encoder | JSONEncoder.encode | >>> from json.encoder import JSONEncoder | null | |
cpython | cfcd524 | json.encoder | JSONEncoder.encode | >>> JSONEncoder().encode({"foo": ["bar", "baz"]}) | '{"foo": ["bar", "baz"]}' | null |
cpython | cfcd524 | textwrap | TextWrapper.shorten | >>> textwrap.shorten("Hello world!", width=12) | 'Hello world!' | null |
cpython | cfcd524 | textwrap | TextWrapper.shorten | >>> textwrap.shorten("Hello world!", width=11) | 'Hello [...]' | null |
cpython | cfcd524 | turtle | TurtleScreenBase._pointlist | >>> from turtle import * | null | |
cpython | cfcd524 | turtle | TurtleScreenBase._pointlist | >>> getscreen()._pointlist(getturtle().turtle._item) | [(0.0, 9.9999999999999982), (0.0, -9.9999999999999982),
(9.9999999999999982, 0.0)] | null |
cpython | cfcd524 | turtle | TurtleScreenBase._pointlist | >>> | null | |
cpython | cfcd524 | turtle | TurtleScreenBase.mainloop | >>> screen.mainloop() | null | |
cpython | cfcd524 | turtle | TurtleScreenBase.textinput | >>> screen.textinput("NIM", "Name of first player:") | null | |
cpython | cfcd524 | turtle | TurtleScreenBase.numinput | >>> screen.numinput("Poker", "Your stakes:", 1000, minval=10, maxval=10000) | null | |
cpython | cfcd524 | turtle | Shape.addcomponent | >>> poly = ((0,0),(10,-5),(0,10),(-10,-5)) | null | |
cpython | cfcd524 | turtle | Shape.addcomponent | >>> s = Shape("compound") | null | |
cpython | cfcd524 | turtle | Shape.addcomponent | >>> s.addcomponent(poly, "red", "blue") | null | |
cpython | cfcd524 | turtle | Shape.addcomponent | >>> # .. add more components and then use register_shape() | null | |
cpython | cfcd524 | turtle | TurtleScreen.clear | >>> screen.clear() | Note: this method is not available as function. | null |
cpython | cfcd524 | turtle | TurtleScreen.mode | >>> mode('logo') # resets turtle heading to north | null | |
cpython | cfcd524 | turtle | TurtleScreen.mode | >>> mode() | 'logo' | null |
cpython | cfcd524 | turtle | TurtleScreen.setworldcoordinates | >>> screen.setworldcoordinates(-10,-0.5,50,1.5) | null | |
cpython | cfcd524 | turtle | TurtleScreen.setworldcoordinates | >>> for _ in range(36):
... left(10)
... forward(0.5) | null | |
cpython | cfcd524 | turtle | TurtleScreen.register_shape | >>> screen.register_shape("triangle", ((5,-3),(0,5),(-5,-3))) | null | |
cpython | cfcd524 | turtle | TurtleScreen.colormode | >>> screen.colormode() | 1.0 | null |
cpython | cfcd524 | turtle | TurtleScreen.colormode | >>> screen.colormode(255) | null | |
cpython | cfcd524 | turtle | TurtleScreen.colormode | >>> pencolor(240,160,80) | null | |
cpython | cfcd524 | turtle | TurtleScreen.reset | >>> screen.reset() | null | |
cpython | cfcd524 | turtle | TurtleScreen.turtles | >>> screen.turtles() | [<turtle.Turtle object at 0x00E11FB0>] | null |
cpython | cfcd524 | turtle | TurtleScreen.bgcolor | >>> screen.bgcolor("orange") | null | |
cpython | cfcd524 | turtle | TurtleScreen.bgcolor | >>> screen.bgcolor() | 'orange' | null |
cpython | cfcd524 | turtle | TurtleScreen.bgcolor | >>> colormode(255) | null | |
cpython | cfcd524 | turtle | TurtleScreen.bgcolor | >>> screen.bgcolor('#800080') | null | |
cpython | cfcd524 | turtle | TurtleScreen.bgcolor | >>> screen.bgcolor() | (128.0, 0.0, 128.0) | null |
cpython | cfcd524 | turtle | TurtleScreen.tracer | >>> screen.tracer(8, 25) | null | |
cpython | cfcd524 | turtle | TurtleScreen.tracer | >>> dist = 2 | null | |
cpython | cfcd524 | turtle | TurtleScreen.tracer | >>> for i in range(200):
... fd(dist)
... rt(90)
... dist += 2 | null | |
cpython | cfcd524 | turtle | TurtleScreen.delay | >>> screen.delay(15) | null | |
cpython | cfcd524 | turtle | TurtleScreen.delay | >>> screen.delay() | 15 | null |
cpython | cfcd524 | turtle | TurtleScreen.no_animation | >>> with screen.no_animation():
... turtle.circle(50) | null | |
cpython | cfcd524 | turtle | TurtleScreen.window_width | >>> screen.window_width() | 640 | null |
cpython | cfcd524 | turtle | TurtleScreen.window_height | >>> screen.window_height() | 480 | null |
cpython | cfcd524 | turtle | TurtleScreen.getcanvas | >>> cv = screen.getcanvas() | null | |
cpython | cfcd524 | turtle | TurtleScreen.getcanvas | >>> cv | <turtle.ScrolledCanvas instance at 0x010742D8> | null |
cpython | cfcd524 | turtle | TurtleScreen.getshapes | >>> screen.getshapes() | ['arrow', 'blank', 'circle', ... , 'turtle'] | null |
cpython | cfcd524 | turtle | TurtleScreen.onclick | >>> screen.onclick(goto) | null | |
cpython | cfcd524 | turtle | TurtleScreen.onclick | >>> # Subsequently clicking into the TurtleScreen will | null | |
cpython | cfcd524 | turtle | TurtleScreen.onclick | >>> # make the turtle move to the clicked point. | null | |
cpython | cfcd524 | turtle | TurtleScreen.onclick | >>> screen.onclick(None) | null | |
cpython | cfcd524 | turtle | TurtleScreen.onkey | >>> def f():
... fd(50)
... lt(60)
... | null | |
cpython | cfcd524 | turtle | TurtleScreen.onkey | >>> screen.onkey(f, "Up") | null | |
cpython | cfcd524 | turtle | TurtleScreen.onkey | >>> screen.listen() | Subsequently the turtle can be moved by repeatedly pressing
the up-arrow key, consequently drawing a hexagon | null |
cpython | cfcd524 | turtle | TurtleScreen.onkeypress | >>> def f():
... fd(50)
... lt(60)
... | null | |
cpython | cfcd524 | turtle | TurtleScreen.onkeypress | >>> screen.onkeypress(f, "Up") | null | |
cpython | cfcd524 | turtle | TurtleScreen.onkeypress | >>> screen.listen() | Subsequently the turtle can be moved by repeatedly pressing
the up-arrow key, or by keeping pressed the up-arrow key.
consequently drawing a hexagon. | null |
cpython | cfcd524 | turtle | TurtleScreen.listen | >>> screen.listen() | null | |
cpython | cfcd524 | turtle | TurtleScreen.ontimer | >>> running = True | null | |
cpython | cfcd524 | turtle | TurtleScreen.ontimer | >>> def f():
... if running:
... fd(50)
... lt(60)
... screen.ontimer(f, 250)
... | null | |
cpython | cfcd524 | turtle | TurtleScreen.ontimer | >>> f() # makes the turtle marching around | null | |
cpython | cfcd524 | turtle | TurtleScreen.ontimer | >>> running = False | null | |
cpython | cfcd524 | turtle | TurtleScreen.bgpic | >>> screen.bgpic() | 'nopic' | null |
cpython | cfcd524 | turtle | TurtleScreen.bgpic | >>> screen.bgpic("landscape.gif") | null | |
cpython | cfcd524 | turtle | TurtleScreen.bgpic | >>> screen.bgpic() | 'landscape.gif' | null |
cpython | cfcd524 | turtle | TurtleScreen.screensize | >>> turtle.screensize(2000,1500) | null | |
cpython | cfcd524 | turtle | TurtleScreen.screensize | >>> # e.g. to search for an erroneously escaped turtle ;-) | null | |
cpython | cfcd524 | turtle | TurtleScreen.save | >>> screen.save('my_drawing.eps') | null | |
cpython | cfcd524 | turtle | TNavigator.degrees | >>> turtle.left(90) | null | |
cpython | cfcd524 | turtle | TNavigator.degrees | >>> turtle.heading() | 90
Change angle measurement unit to grad (also known as gon,
grade, or gradian and equals 1/100-th of the right angle.) | null |
cpython | cfcd524 | turtle | TNavigator.degrees | >>> turtle.degrees(400.0) | null | |
cpython | cfcd524 | turtle | TNavigator.degrees | >>> turtle.heading() | 100 | null |
cpython | cfcd524 | turtle | TNavigator.radians | >>> turtle.heading() | 90 | null |
cpython | cfcd524 | turtle | TNavigator.radians | >>> turtle.radians() | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.