Is it possible to create anonymous objects in Python?

前端 未结 11 584
余生分开走
余生分开走 2020-12-14 13:58

I\'m debugging some Python that takes, as input, a list of objects, each with some attributes.

I\'d like to hard-code some test values -- let\'s say, a list of four

11条回答
  •  一整个雨季
    2020-12-14 14:47

    Maybe you can use namedtuple to solve this as following:

    from collections import namedtuple
    Mock = namedtuple('Mock', ['foo'])
    
    mock = Mock(foo=1)
    mock.foo  // 1
    

提交回复
热议问题