Namedtuple like class

后端 未结 5 1933
有刺的猬
有刺的猬 2021-02-06 01:27

I find myself writing this class often in my python code when I need a quick single use class.

class Struct(object):
   def __init__( self, **kwargs ):
      for          


        
5条回答
  •  故里飘歌
    2021-02-06 02:08

    There is a python recipe for this (It just updates the instance's dict instead of calling setattr) Recipe 52308

    class Bunch(object):
        def __init__(self, **kwds):
            self.__dict__.update(kwds)
    

提交回复
热议问题