mirror of
https://github.com/donnemartin/data-science-ipython-notebooks.git
synced 2024-03-22 13:30:56 +08:00
Added discussion of closures being used for decorators and the usefulness of decorators.
This commit is contained in:
parent
2de3d867c4
commit
54b1c29bcc
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"metadata": {
|
||||
"name": "",
|
||||
"signature": "sha256:d9028f29469f49a645af74dd1ee28614caee8ca7ca47089925560fa874a2384b"
|
||||
"signature": "sha256:1123ef3475d906de39c34c42c18ebeda8c0f1c60ee01b6e692125a51b325d8e7"
|
||||
},
|
||||
"nbformat": 3,
|
||||
"nbformat_minor": 0,
|
||||
|
@ -226,7 +226,17 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Closures are dynamically-genearated functions returned by another function. The returned function has access to the variables in the local namespace where it was created."
|
||||
"Closures are dynamically-genearated functions returned by another function. The returned function has access to the variables in the local namespace where it was created. \n",
|
||||
"\n",
|
||||
"Closures are often used to implement decorators. Decorators are useful to transparently wrap something with additional functionality:\n",
|
||||
"\n",
|
||||
"```python\n",
|
||||
"def my_decorator(fun):\n",
|
||||
" def myfun(*params, **kwparams):\n",
|
||||
" do_something()\n",
|
||||
" fun(*params, **kwparams)\n",
|
||||
" return myfun\n",
|
||||
"```"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user