python
Decorator
Define the decorator: The decorator
function wraps another function (func
) with extra behavior before and after calling it.
def my_decorator(func):
def wrapper():
print("Before the function runs")
func()
print("After the function runs")
return wrapper
@my_decorator
def say_hello():
print("Hello!")
say_hello()
Before the function runs
Hello!
After the function runs
- json.dumps(): 对象→JSON字符串(内存中)
- json.loads(): JSON字符串→对象(内存中)
- json.dump(): 对象→JSON文件
- json.load(): JSON文件→对象