[Chicago] Inheriting from a namedtuple

Aaron Elmquist elmq0022 at umn.edu
Thu Jul 7 19:34:07 EDT 2016


Basically, I was reading someone else code (chess engine called sunfish)
and saw this.

I went back to the python namedtuple docs and saw it as an example.  So I
know it is possible and possibly pythonic.

But, I have the same question as you Adam, why not use slots instead?

I am not seeing any advantages straight away.

Aaron
On Jul 7, 2016 6:20 PM, "Adam Forsyth" <adam at adamforsyth.net> wrote:

> Why namedtuple instead of __slots__? What are you getting from namedtuple?
>
> If you do have a good reason to use namedtuple, I think it's OK to use it
> like this -- it reads clearly to me, and is easy to refactor. However, I
> would call the base class "PointBase" rather than "Point".
>
> Adam
>
> On Thu, Jul 7, 2016 at 5:58 PM, Aaron Elmquist <elmq0022 at umn.edu> wrote:
>
>> This is a very open ended question, but what do people think about python
>> code like:
>>
>> class Point(namedtuple("Point", "x y")):
>>     # additional methods here
>>
>> Is it pythonic?
>>
>> Does it buy anything besides keystrokes?
>>
>> Do you use it in production?
>>
>> Thanks,
>>
>> Aaron
>>
>> _______________________________________________
>> Chicago mailing list
>> Chicago at python.org
>> https://mail.python.org/mailman/listinfo/chicago
>>
>>
>
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> https://mail.python.org/mailman/listinfo/chicago
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20160707/adb6ecc1/attachment.html>


More information about the Chicago mailing list