装饰器的问题:为什么调用不加括号,还只能用静态方法?
def login(func):
def inner():
name=input("用户名:")
pw=input("密码:")
if name=="Skyyy"and pw=="sb":
func()
else:
print("gun!!!")
return inner()
class Person:
@login
@staticmethod
def f2():
print("\(@^0^@)/")
Person.f2
print("*"*10)
Person.f2()
运行结果:
D:\Skyyy\venv\Scripts\python.exe D:/Skyyy/Warmup/Let's_start.py
用户名:Skyyy
密码:sb
\(@^0^@)/
**********
Traceback (most recent call last):
File "D:\Skyyy\Warmup\Let's_start.py", line 2119, in <module>
Person.f2()
TypeError: 'NoneType' object is not callable
进程已结束,退出代码1