【发布时间】:2018-02-06 01:19:40
【问题描述】:
我有一个带有几个初始化变量的 python 类:
class Foo(object):
def __init__(self, d1, d2):
self.d1 = d1
self.d2 = d2
有没有办法在 PyCharm 中自动创建这段代码,所以我不必显式输入:
self.dn = dn
这种模式在我的代码中经常出现。有没有更好的(Pythonic)方法来初始化类?
我已经看过这篇文章 (What is the best way to do automatic attribute assignment in Python, and is it a good idea?),但我不想使用装饰器,因为它会降低代码的可读性。
【问题讨论】:
标签: python class attributes pycharm