Immutability and Python

Chris Angelico rosuav at gmail.com
Mon Oct 29 15:36:52 EDT 2012


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')):

You lose the unnecessary temporary and triplication of name, but gain
instead a rather long line.

ChrisA



More information about the Python-list mailing list