社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

luther

luther 最近创建的主题
luther 最近回复了
8 年前
回复了 luther 创建的主题 » 如何使用构造函数关键字参数指定python类属性

我相信没有装饰者你可以做到这一点:

class Specifiable:

  def __init__(self, **kwargs):
    for key, value in kwargs.items():
      setattr(self, key, value)


class BlankStruct(Specifiable):

  def __init__(self, **kwargs):
    super().__init__(**kwargs)
    # Do other stuff.