而不是每次我定义一个类时都编写这样的代码:
class Foo(object):
def __init__(self, a, b, c, d, e, f, g):
self.a = a
self.b = b
self.c = c
self.d = d
self.e = e
self.f = f
self.g = g
Run Code Online (Sandbox Code Playgroud)
我可以使用此配方进行自动属性分配.
class Foo(object):
@autoassign
def __init__(self, a, b, c, d, e, f, g):
pass
Run Code Online (Sandbox Code Playgroud)
两个问题: