On Wed, May 9, 2012 at 8:50 AM, Antoine Pitrou <solip...@pitrou.net> wrote:
> On Wed, 9 May 2012 10:44:59 -0400
> Brett Cannon <br...@python.org> wrote:
>>
>> > I wish there was a builtin class
>> >
>> >     class record:
>> >        pass
>> >
>> >   which can be used to create objects which have only attributes
>> >   and no methods.
>>
>>
>> I have heard this request now a bazillion times over the years. Why don't
>> we have such an empty class sitting somewhere in the stdlib with a
>> constructor classmethod to simply return new instances (and if you want to
>> get really fancy, optional keyword arguments to update the instance with
>> the keys/values passed in)? Is it simply because it's just two lines of
>> Python that *everyone* has replicated at some point?
>
> In this case, it's because sys is a built-in module written in C, and
> importing Python code is a no-go.

Something I've remotely considered is an approach like namedtuple
takes: define a pure Python template, .format() it, and exec it.
However, this is partly a reflection of my lack of familiarity with
using the C-API. As well, the only place I've seen this done in the
CPython code base is with namedtuple.  Consequently, I was planning on
taking the normal approach.  Should the namedtuple-exec technique be
avoided at the C level?

-eric
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to