2020-10-19 21:08:55

This commit is contained in:
wizardforcel
2020-10-19 21:08:55 +08:00
parent 7f63048035
commit ab0caba1f0
140 changed files with 3982 additions and 3982 deletions

View File

@@ -6,7 +6,7 @@
In [1]:
```
```py
class Foo(object):
@classmethod
def bar(cls, x):
@@ -21,12 +21,12 @@ class Foo(object):
In [2]:
```
```py
Foo.bar(12)
```
```
```py
the input is 12
```
@@ -37,7 +37,7 @@ the input is 12
In [3]:
```
```py
class Foo(object):
def __init__(self, data):
self.data = data
@@ -52,7 +52,7 @@ class Foo(object):
In [4]:
```
```py
foo = Foo(23)
foo.x
@@ -60,7 +60,7 @@ foo.x
Out[4]:
```
```py
23
```
@@ -68,12 +68,12 @@ Out[4]:
In [5]:
```
```py
foo.x = 1
```
```
```py
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-5-e5e7e6c675ef> in <module>()
@@ -86,7 +86,7 @@ AttributeError: can't set attribute
In [6]:
```
```py
class Foo(object):
def __init__(self, data):
self.data = data
@@ -103,13 +103,13 @@ class Foo(object):
In [7]:
```
```py
foo = Foo(23)
print foo.x
```
```
```py
23
```
@@ -118,13 +118,13 @@ print foo.x
In [8]:
```
```py
foo.x = 1
print foo.x
```
```
```py
1
```
@@ -135,7 +135,7 @@ print foo.x
In [9]:
```
```py
from numpy import vectorize, arange
@vectorize
@@ -151,7 +151,7 @@ f(arange(-10.0,10.0))
Out[9]:
```
```py
array([-10., -9., -8., -7., -6., -5., -4., -3., -2., -1., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0.])
```
@@ -162,7 +162,7 @@ array([-10., -9., -8., -7., -6., -5., -4., -3., -2., -1., 0.,
In [10]:
```
```py
class Registry(object):
def __init__(self):
self._data = {}
@@ -180,7 +180,7 @@ class Registry(object):
In [11]:
```
```py
registry = Registry()
```
@@ -189,7 +189,7 @@ registry = Registry()
In [12]:
```
```py
@registry.register
def greeting():
print "hello world"
@@ -200,27 +200,27 @@ def greeting():
In [13]:
```
```py
registry._data
```
Out[13]:
```
```py
{'greeting': <function __main__.greeting>}
```
In [14]:
```
```py
registry.greeting
```
Out[14]:
```
```py
<function __main__.greeting>
```
@@ -232,7 +232,7 @@ Out[14]:
In [15]:
```
```py
def logging_call(f):
def wrapper(*a, **kw):
print 'calling {}'.format(f.__name__)
@@ -250,7 +250,7 @@ print square.__doc__, square.__name__
```
```
```py
None wrapper
```
@@ -261,7 +261,7 @@ None wrapper
In [16]:
```
```py
import functools
def logging_call(f):
@@ -282,7 +282,7 @@ print square.__doc__, square.__name__
```
```
```py
square function.
square