A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2017-July/148629.html below:

[Python-Dev] Impact of Namedtuple on startup time

[Python-Dev] Impact of Namedtuple on startup timeAlexander Belopolsky alexander.belopolsky at gmail.com
Mon Jul 17 19:48:05 EDT 2017
On Mon, Jul 17, 2017 at 6:27 PM, Greg Ewing <greg.ewing at canterbury.ac.nz>
wrote:
>
>
> Maybe a metaclass could be used to make something
> like this possible:
>
>
>    class Foo(NamedTuple, fields = 'x,y,z'):
>       ...
>
>
If you think of it, collection.namedtuple *is* a metaclass.  A simple
wrapper will make it usable as such:

import collections

def namedtuple(name, bases, attrs, fields=()):
        # Override __init_subclass__ for Python 3.6
        return collections.namedtuple(name, fields)

class Foo(metaclass=namedtuple, fields='x,y'):
    pass

print(Foo(1, 2))   # ---> Foo(x=1, y=2)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20170717/a08bf4e1/attachment.html>
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4