my own type in C, sequence protocol

Heiko Wundram heikowu at ceosg.de
Thu Sep 9 23:01:46 CEST 2004


Am Donnerstag, 9. September 2004 22:21 schrieb Torsten Mohr:
> The type that i implemented is a "CAN message", don't know
> if this means something to you, it is a communication message
> with 0 to 8 bytes content.  To access this content i thought
> there would be an advantage in implementing the sequence
> protocol.  What is the advantage then?

I don't know what a CAN message is, but implementing the sequence protocol 
certainly has its features.

What you can do to reassign the whole of m:

m[:] = [1,2,3]

Now, if you implemented the sequence protocol correctly (meaning it can deal 
with slices, this will reassign the whole of m. Lists support slice 
assignment:

>>> x = [1,2,3]
>>> id(x)
-1477186996
>>> x[:] = [4,5,6]
>>> x
[4, 5, 6]
>>> id(x)
-1477186996

(see how x is not rebound?)

Well, anyway, maybe you can just paste some example code (a more thorough 
explanation would also be okay) for us to see, so that we know what you're 
trying to do, and then suggest a proper idiom to use... Currently I can't 
really grasp what you need the sequence protocol for...

Heiko.



More information about the Python-list mailing list