What is the best way to do automatic attribute assignment in Python, and is it a good idea?

前端 未结 10 1412
深忆病人
深忆病人 2020-11-30 00:00

Instead of writing code like this every time I define a class:

class Foo(object): 
     def __init__(self, a, b, c, d, e, f, g):
        self.a = a
        s         


        
10条回答
  •  囚心锁ツ
    2020-11-30 00:16

    One drawback: many IDEs parse __init__.py to discover an object's attributes. If you want automatic code completion in your IDE to be more functional, then you may be better off spelling it out the old-fashioned way.

提交回复
热议问题