Skip to content

Commit bc354ce

Browse files
committed
更改md
1 parent 07eff77 commit bc354ce

File tree

1 file changed

+117
-63
lines changed

1 file changed

+117
-63
lines changed

decorator.ipynb

Lines changed: 117 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"### 静态方法和类成员方法分别在创建时分别被装入staticmethod类型和classmethod类型的对象中。\n",
7+
"**静态方法和类成员方法分别在创建时分别被装入staticmethod类型和classmethod类型的对象中。**\n",
88
"\n",
9-
"### 静态方法的定义没有self参数,且能够被类本身直接调用。\n",
9+
"**静态方法的定义没有self参数,且能够被类本身直接调用。**\n",
1010
"\n",
1111
"\n",
12-
"### 类方法在定义时需要名为cls的类似于self的参数,类成员方法可以直接用类的具体对象调用。但cls参数时自动被绑定到类的。"
12+
"**类方法在定义时需要名为cls的类似于self的参数,类成员方法可以直接用类的具体对象调用。但cls参数时自动被绑定到类的。**"
1313
]
1414
},
1515
{
@@ -68,14 +68,14 @@
6868
"source": [
6969
"手动包装和替换优点蠢!为这样的包装方法引入了一个叫装饰器的新语法。\n",
7070
"\n",
71-
"### 装饰器能对任何可调用的对象进行包装,既能够用于方法也能用于函数。"
71+
"**装饰器能对任何可调用的对象进行包装,既能够用于方法也能用于函数。**"
7272
]
7373
},
7474
{
7575
"cell_type": "markdown",
7676
"metadata": {},
7777
"source": [
78-
"### 使用@操作符,在方法(函数)的上方将装饰器列出,从而指定一个或者更多的装饰器(多个装饰器在应用时的顺序与指定顺序相反)。"
78+
"**使用`@`操作符,在方法(函数)的上方将装饰器列出,从而指定一个或者更多的装饰器(多个装饰器在应用时的顺序与指定顺序相反)。**"
7979
]
8080
},
8181
{
@@ -154,9 +154,11 @@
154154
"cell_type": "markdown",
155155
"metadata": {},
156156
"source": [
157-
"##### @decorator(dec_opt_args)\n",
158-
"##### def fun2Bdecorator(func_opt_args):\n",
159-
" ...."
157+
"```python\n",
158+
"@decorator(dec_opt_args)\n",
159+
"def fun2Bdecorator(func_opt_args):\n",
160+
" pass\n",
161+
"```"
160162
]
161163
},
162164
{
@@ -170,10 +172,12 @@
170172
"cell_type": "markdown",
171173
"metadata": {},
172174
"source": [
173-
"##### @deco2\n",
174-
"##### @deco1\n",
175-
"##### def(arg1, arg2, ...):\n",
176-
" pass"
175+
"```python\n",
176+
"@deco2\n",
177+
"@deco1\n",
178+
"def(arg1, arg2[,..]):\n",
179+
" pass\n",
180+
"```"
177181
]
178182
},
179183
{
@@ -187,9 +191,13 @@
187191
"cell_type": "markdown",
188192
"metadata": {},
189193
"source": [
190-
"##### def func(arg1, arg2, ...):\n",
191-
" pass\n",
192-
"##### func = deco2(deco1(func))"
194+
"```python\n",
195+
"def func(arg1, arg2, ...):\n",
196+
" pass\n",
197+
"```\n",
198+
"```python\n",
199+
"func = deco2(deco1(func))\n",
200+
"```"
193201
]
194202
},
195203
{
@@ -205,11 +213,17 @@
205213
"cell_type": "markdown",
206214
"metadata": {},
207215
"source": [
208-
"##### @g\n",
209-
"##### @f\n",
210-
"##### def foo():\n",
216+
"```python\n",
217+
"@g\n",
218+
"@f\n",
219+
"def foo():\n",
211220
" pass\n",
212-
"##### 与foo = g(f(foo))相同"
221+
"```\n",
222+
"\n",
223+
"```python\n",
224+
"foo = g(f(foo))\n",
225+
"```\n",
226+
"相同"
213227
]
214228
},
215229
{
@@ -223,8 +237,11 @@
223237
"cell_type": "markdown",
224238
"metadata": {},
225239
"source": [
226-
"#### @deco\n",
227-
"#### def foo(): pass"
240+
"```python\n",
241+
"@deco\n",
242+
"def foo():\n",
243+
" pass\n",
244+
"```"
228245
]
229246
},
230247
{
@@ -238,8 +255,11 @@
238255
"cell_type": "markdown",
239256
"metadata": {},
240257
"source": [
241-
"#### @decomaker(deco_args)\n",
242-
"#### def foo(): pass"
258+
"```python\n",
259+
"@decomaker(deco_args)\n",
260+
"def foo():\n",
261+
" pass\n",
262+
"```"
243263
]
244264
},
245265
{
@@ -253,7 +273,9 @@
253273
"cell_type": "markdown",
254274
"metadata": {},
255275
"source": [
256-
"#### foo = decomaker(deco_args)(foo)"
276+
"```python\n",
277+
"foo = decomaker(deco_args)(foo)\n",
278+
"```"
257279
]
258280
},
259281
{
@@ -267,9 +289,12 @@
267289
"cell_type": "markdown",
268290
"metadata": {},
269291
"source": [
270-
"#### @deco1(deco_arg)\n",
271-
"#### @deco2\n",
272-
"#### def func(): pass"
292+
"```python\n",
293+
"@deco1(deco_arg)\n",
294+
"@deco2\n",
295+
"def func():\n",
296+
" pass\n",
297+
"```"
273298
]
274299
},
275300
{
@@ -290,64 +315,93 @@
290315
"cell_type": "markdown",
291316
"metadata": {},
292317
"source": [
293-
"#### 引入日志"
294-
]
295-
},
296-
{
297-
"cell_type": "markdown",
298-
"metadata": {},
299-
"source": [
300-
"#### 增加计逻辑来检测性能"
301-
]
302-
},
303-
{
304-
"cell_type": "markdown",
305-
"metadata": {},
306-
"source": [
307-
"#### 给函数加入事务的能力"
308-
]
309-
},
310-
{
311-
"cell_type": "markdown",
312-
"metadata": {},
313-
"source": [
318+
"+ 引入日志\n",
319+
"\n",
320+
"+ 增加计逻辑来检测性能\n",
321+
"\n",
322+
"+ 给函数加入事务的能力\n",
323+
"\n",
314324
"对于用python创建企业级应用,支持装饰器的特性是非常重要的。"
315325
]
316326
},
317327
{
318328
"cell_type": "markdown",
319329
"metadata": {},
320330
"source": [
321-
"## 装饰器本质上是一个python函数, 可以让其他函数再不需要做任何代码变动的前提下增加额外功能。即装饰器的作用就是为已经存在的对象添加额外的功能。"
331+
"**装饰器本质上是一个python函数, 可以让其他函数再不需要做任何代码变动的前提下增加额外功能。即装饰器的作用就是为已经存在的对象添加额外的功能。**"
322332
]
323-
},
324-
{
325-
"cell_type": "code",
326-
"execution_count": null,
327-
"metadata": {
328-
"collapsed": true
329-
},
330-
"outputs": [],
331-
"source": []
332333
}
333334
],
334335
"metadata": {
336+
"hide_input": false,
335337
"kernelspec": {
336-
"display_name": "Python 2",
338+
"display_name": "Python 3",
337339
"language": "python",
338-
"name": "python2"
340+
"name": "python3"
339341
},
340342
"language_info": {
341343
"codemirror_mode": {
342344
"name": "ipython",
343-
"version": 2
345+
"version": 3
344346
},
345347
"file_extension": ".py",
346348
"mimetype": "text/x-python",
347349
"name": "python",
348350
"nbconvert_exporter": "python",
349-
"pygments_lexer": "ipython2",
350-
"version": "2.7.13"
351+
"pygments_lexer": "ipython3",
352+
"version": "3.6.8"
353+
},
354+
"nbTranslate": {
355+
"displayLangs": [
356+
"*"
357+
],
358+
"hotkey": "alt-t",
359+
"langInMainMenu": true,
360+
"sourceLang": "en",
361+
"targetLang": "fr",
362+
"useGoogleTranslate": true
363+
},
364+
"toc": {
365+
"base_numbering": 1,
366+
"nav_menu": {},
367+
"number_sections": true,
368+
"sideBar": true,
369+
"skip_h1_title": false,
370+
"title_cell": "Table of Contents",
371+
"title_sidebar": "Contents",
372+
"toc_cell": false,
373+
"toc_position": {},
374+
"toc_section_display": true,
375+
"toc_window_display": false
376+
},
377+
"varInspector": {
378+
"cols": {
379+
"lenName": 16,
380+
"lenType": 16,
381+
"lenVar": 40
382+
},
383+
"kernels_config": {
384+
"python": {
385+
"delete_cmd_postfix": "",
386+
"delete_cmd_prefix": "del ",
387+
"library": "var_list.py",
388+
"varRefreshCmd": "print(var_dic_list())"
389+
},
390+
"r": {
391+
"delete_cmd_postfix": ") ",
392+
"delete_cmd_prefix": "rm(",
393+
"library": "var_list.r",
394+
"varRefreshCmd": "cat(var_dic_list()) "
395+
}
396+
},
397+
"types_to_exclude": [
398+
"module",
399+
"function",
400+
"builtin_function_or_method",
401+
"instance",
402+
"_Feature"
403+
],
404+
"window_display": false
351405
}
352406
},
353407
"nbformat": 4,

0 commit comments

Comments
 (0)