我希望将一个普通的旧函数作为类常量.但是,Python"有帮助"将它变成了一种方法:
class C(object):
a = 17
b = (lambda x : x+1)
print C.a # Works fine for int attributes
print C.b # Uh-oh... is a <unbound method C.<lambda>> now
print C.b(1) # TypeError: unbound method <lambda>() must be called
# with C instance as first argument (got int instance instead)
Run Code Online (Sandbox Code Playgroud)