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
As of Python 3.3, there's types.SimpleNamespace that does exactly what you want:
myfunc([types.SimpleNamespace(foo=1), types.SimpleNamespace(foo=2), types.SimpleNamespace(foo=3), types.SimpleNamespace(foo=4)])
That's a tad wordy, but you can clean it up with an alias:
_ = types.SimpleNamespace
myfunc([_(foo=1), _(foo=2), _(foo=3), _(foo=4)])
And now that's actually pretty close to the fictional syntax in your question.