Hi Petr, hi Paul,
the struct sequence objects are in fact interesting!
About the "every instance" issue:
Well, if I used something like the caching approach from Paul's post,
like
cached_namedtuple = lru_cache(None)(namedtuple)
n1 = cached_namedtuple('f', ('a', 'b', 'c'))
n2 = cached_namedtuple('f', ('a', 'b', 'c'))
n1 is n2
which produces uniqueness, then I would need no explicit names.
How about that principle, but with the struct sequence objects?
Cheers -- Chris
On 30.07.19 11:13, Petr Viktorin wrote:
> Hello,
> I'm afraid you're stuck with defining a new type for each of these.
> One reason why that's better is that info about the names will only be
> stored once, in the type; not in every instance.
>
> Since this is in PySide, I assume you're using the C-API. If that's the
> case, check out Struct Sequences, the "C equivalent of named tuples".
> For example, the result of "os.stat()" is a struct sequence.
>
> https://docs.python.org/3/c-api/tuple.html#struct-sequence-objects
>
> Note that like namedtuples, these are immutable, and they're proper
> subclasses of tuple.
--
Christian Tismer :^) [email protected]
Software Consulting : http://www.stackless.com/
Karl-Liebknecht-Str. 121 : https://github.com/PySide
14482 Potsdam : GPG key -> 0xFB7BEE0E
phone +49 173 24 18 776 fax +49 (30) 700143-0023
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/WL3M2UGYXO5EZ5G7OUQAYUDRLLEG7TRQ/