Skip to content

Commit 2bda2af

Browse files
committed
Add initial version of IPy notebook on object
1 parent 6878c54 commit 2bda2af

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
{
2+
"metadata": {
3+
"name": ""
4+
},
5+
"nbformat": 3,
6+
"nbformat_minor": 0,
7+
"worksheets": [
8+
{
9+
"cells": [
10+
{
11+
"cell_type": "heading",
12+
"level": 2,
13+
"metadata": {},
14+
"source": [
15+
"``object`` special methods"
16+
]
17+
},
18+
{
19+
"cell_type": "code",
20+
"collapsed": false,
21+
"input": [
22+
"import sys\n",
23+
"sys.version"
24+
],
25+
"language": "python",
26+
"metadata": {},
27+
"outputs": [
28+
{
29+
"metadata": {},
30+
"output_type": "pyout",
31+
"prompt_number": 4,
32+
"text": [
33+
"'2.7.6 |Continuum Analytics, Inc.| (default, Jan 17 2014, 10:13:17) \\n[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)]'"
34+
]
35+
}
36+
],
37+
"prompt_number": 4
38+
},
39+
{
40+
"cell_type": "code",
41+
"collapsed": false,
42+
"input": [
43+
"from future.builtins import object"
44+
],
45+
"language": "python",
46+
"metadata": {},
47+
"outputs": [],
48+
"prompt_number": 1
49+
},
50+
{
51+
"cell_type": "code",
52+
"collapsed": false,
53+
"input": [
54+
"object??"
55+
],
56+
"language": "python",
57+
"metadata": {},
58+
"outputs": [],
59+
"prompt_number": 2
60+
},
61+
{
62+
"cell_type": "code",
63+
"collapsed": false,
64+
"input": [
65+
"# Py3-style iterators written as new-style classes (subclasses of\n",
66+
"# future.builtins.object) are backward compatibile with Py2:\n",
67+
"class Upper(object):\n",
68+
" def __init__(self, iterable):\n",
69+
" self._iter = iter(iterable)\n",
70+
" def __next__(self): # note the Py3 interface\n",
71+
" return next(self._iter).upper()\n",
72+
" def __iter__(self):\n",
73+
" return self\n",
74+
"\n",
75+
"assert list(Upper('hello')) == list('HELLO')"
76+
],
77+
"language": "python",
78+
"metadata": {},
79+
"outputs": [],
80+
"prompt_number": 3
81+
},
82+
{
83+
"cell_type": "code",
84+
"collapsed": false,
85+
"input": [],
86+
"language": "python",
87+
"metadata": {},
88+
"outputs": []
89+
}
90+
],
91+
"metadata": {}
92+
}
93+
]
94+
}

0 commit comments

Comments
 (0)