为什么Callable()会抛出异常?? 百度没找到答案
Topic source__call__()是能够让我们直接进行实例调用,即:
s('name')
而不是Callable(s)这样的代码,
当然可以写Callable('string'),这里参数不应该是你定义的实例s。
不过这个就和__call__()没有关系了。
楼主可能混淆了“实例()” 和 “类()”
- 1
__call__()是能够让我们直接进行实例调用,即:
s('name')
而不是Callable(s)这样的代码,
当然可以写Callable('string'),这里参数不应该是你定义的实例s。
不过这个就和__call__()没有关系了。
楼主可能混淆了“实例()” 和 “类()”
旭_317
class Student(object): def init(self, name): self.name = name
s = Student('zhangsan') print(Callable(s))
D:\Anaconda3\python.exe E:/ProgramDesign/PyProgram/Test/main.py Traceback (most recent call last): File "E:/Program_Design/Py_Program/Test/main.py", line 14, in <module> print(Callable(s)) File "D:\Anaconda3\lib\typing.py", line 1265, in __new raise TypeError("Type Callable cannot be instantiated; " TypeError: Type Callable cannot be instantiated; use a non-abstract subclass instead
Process finished with exit code 1