my own type in C, sequence protocol

Donn Cave donn at
Thu Sep 9 21:48:40 CEST 2004

In article <chq9eg$c2i$1 at>,
 Torsten Mohr <tmohr at> wrote:

> i created a new type and implemented the sequence protocol
> for it, or to be more precise the functions to get the
> sequence length, to read a value and to assign a value
> to an item.
> Now i thought i could assign values to my type like
> this:
> m = myType();
> m = [ 1, 2, 3];
> I have to admit that i'm not really experienced in python.
> Now that i have implemented the sequence protocol, what
> can i do with it, can't i assign values like above somehow?

Nope.  The expression [1, 2, 3] evaluates to a list,
as in listobject.  m = [1, 2, 3] binds the name "m"
to this object.  Its prior binding to your myType()
instance doesn't matter.  If you're new to Python, it's
lucky you ran into this so early, because this business
about names and objects is an important difference between
Python and, for example, C++.

You might want your type's init function to accept a
sequence, to copy for an initial value, as in

 m = myType([1, 2, 3])

   Donn Cave, donn at

More information about the Python-list mailing list