Correct type for a simple "bag of attributes" namespace object (was: 3 Suggestions to Make Python Easier For Children)

Chris Angelico rosuav at gmail.com
Sat Aug 2 17:05:39 EDT 2014


On Sun, Aug 3, 2014 at 6:46 AM, Mark Summerfield <list at qtrac.plus.com> wrote:
> But perhaps what I should be asking for is for a new built-in that does what types.SimpleNamespace() does, so that without any import you can write, say,
>
> foo = namespace(a=1, b=2)
> # or
> bar = namespace()
> bar.a = 1
>
> where under the hood namespace has the same behavior as types.SimpleNamespace().
>
> Naturally, I understand that adding a new name is a big deal and may be too much to ask for beginners.

This is where you might want to consider putting some imports into
site.py. That way, you can set up your own customized Python, without
waiting for changes to be approved for core (which they probably won't
- new builtins have a high requirement for necessity, not just "I
don't want to have to type import").

ChrisA



More information about the Python-list mailing list