Skip to content

Commit 1fbc2e9

Browse files
🗑️ 删除示例代码文件table.py
- 移除了`table.py`文件,该文件包含了查找目标值的示例代码。 - 更新了文档,增加了关于装饰器的详细说明和示例,提升了内容的实用性与可读性。
1 parent cafb1ea commit 1fbc2e9

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

docs/docs/选择编程语言/Python/28装饰器与作用域.mdx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ sidebar_position: 28
33
title: 装饰器与作用域
44
---
55

6-
76
## 装饰器
87

98
### callable函数
@@ -73,9 +72,35 @@ test(1) # 打印test 1
7372

7473
```
7574

75+
:::info
76+
77+
<Highlight>装饰器在被装饰函数定义时执行,而不是在被装饰函数调用时执行</Highlight>。
78+
79+
可以利用这个特性来收集工具函数信息作为大模型的上下文。
80+
81+
```python showLineNumbers
82+
def log(func):
83+
print(func.__name__, func.__doc__)
84+
85+
@log
86+
def test1():
87+
"""test1 function"""
88+
pass
89+
90+
@log
91+
def test2():
92+
pass
93+
"""
94+
输出:
95+
test1 test1 function
96+
test2 None
97+
"""
98+
```
99+
:::
100+
76101
装饰器的其他使用示例:记录函数运行时间、用于自动测试。
77102

78-
```python
103+
```python showLineNumbers
79104
import time
80105

81106
def log(func):

table.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)