Correct type for a simple “bag of attributes” namespace object

Mark Lawrence breamoreboy at yahoo.co.uk
Sun Aug 3 08:28:58 EDT 2014


On 02/08/2014 20:58, Ben Finney wrote:
> Steven D'Aprano <steve+comp.lang.python at pearwood.info> writes:
>
>> If you need instances which carry state, then object is the wrong
>> class.
>
> Right. The ‘types’ module provides a SimpleNamespace class for the
> common “bag of attributes” use case::
>
>      >>> import types
>      >>> foo = types.SimpleNamespace()
>      >>> foo.x = 3
>      >>> foo
>      namespace(x=3)
>
> <URL:https://docs.python.org/3/library/types.html#types.SimpleNamespace>
>

What Alex Martelli called a bunch?

http://code.activestate.com/recipes/52308-the-simple-but-handy-collector-of-a-bunch-of-named/

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence




More information about the Python-list mailing list