Immutability and Python

Steven D'Aprano steve+comp.lang.python at pearwood.info
Mon Oct 29 18:34:29 EDT 2012


On Tue, 30 Oct 2012 06:36:52 +1100, Chris Angelico wrote:

> On Tue, Oct 30, 2012 at 6:23 AM, Ian Kelly <ian.g.kelly at gmail.com>
> wrote:
>> _MyImmutableClass = namedtuple('MyImmutableClass', 'field1 field2
>> field3 field4')
>>
>> class MyImmutableClass(_MyImmutableClass):
> 
> Question: Is it clearer to take advantage of the fact that the base
> class can be an arbitrary expression?
> 
> class MyImmutableClass(namedtuple('MyImmutableClass', 'field1 field2
> field3 field4')):


I'm too lazy to google for it, but if you read the examples provided by 
namedtuple's creator, Raymond Hettinger, that is precisely one of the 
styles he uses. No need to explicitly declare the base class before using 
it.



-- 
Steven



More information about the Python-list mailing list