[Python-ideas] a simple namespace type

Jan Kaliszewski zuo at chopin.edu.pl
Tue May 29 19:34:06 CEST 2012


Eric Snow dixit (2012-05-28, 10:34):

> On Sun, May 27, 2012 at 2:09 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> > Slightly easier bar to reach: could the various incarnations be improved by
> > using a new varobject type as a base class (e.g. I know I often use
> > namedtuple as a base class rather than instantiating them directly, although
> > I do the latter, too).
> 
> Good point.  I do the same.
> 
> > There's also a potentially less controversial alternative: just add an easy
> > spelling for "type(name, (), {})" to the C API.
> 
> I really like this.  There's a lot of boilerplate to create just a
> simple type like this in the C API.  I'll see what I can come up with.
>  :)
> 
> As a namespace, it would be good to have a nice repr, but that's not a
> show stopper.

Using classes as 'attribute containers' is suboptimal (which means that
in performance-critical parts of code you would have to implement a
namespace-like type anyway -- if you wanted to have attr-based syntax,
of course).

There should be one obvious way to do it. Now there is no one.

Cheers.
*j




More information about the Python-ideas mailing list