<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 17, 2017 at 6:27 PM, Greg Ewing <span dir="ltr"><<a href="mailto:greg.ewing@canterbury.ac.nz" target="_blank">greg.ewing@canterbury.ac.nz</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">
<br></span>
Maybe a metaclass could be used to make something<br>
like this possible:<br>
<br>
<br>
   class Foo(NamedTuple, fields = 'x,y,z'):<br>
      ...<br><br>
</blockquote></div><br></div><div class="gmail_extra">If you think of it, collection.namedtuple *is* a metaclass.  A simple wrapper will make it usable as such:</div><div class="gmail_extra"><br></div><div class="gmail_extra"><div class="gmail_extra">import collections</div><div class="gmail_extra"><br></div><div class="gmail_extra">def namedtuple(name, bases, attrs, fields=()):</div><div class="gmail_extra">        # Override __init_subclass__ for Python 3.6</div><div class="gmail_extra">        return collections.namedtuple(name, fields)</div><div class="gmail_extra"><br></div><div class="gmail_extra">class Foo(metaclass=namedtuple, fields='x,y'):</div><div class="gmail_extra">    pass</div><div class="gmail_extra"><br></div><div class="gmail_extra">print(Foo(1, 2))   # ---> Foo(x=1, y=2)</div></div><div class="gmail_extra"><br></div></div>