TypeError: 'function' object is not subscriptable
class Employee:
__job = "industry"
def m1(self):
print("self.__job")
想看看m1函数的字节码:
print(Employee.m1["code"])
您需要使用dis模块:
import dis
class Employee:
__job = "industry"
def m1(self):
print("self.__job")
为什么 Employee.m1["code"] 会报错?
Employee.m1 既是函数,也是对象,函数/方法对象不是容器类型(如 list、dict),不支持下标访问([] 操作)