my own type in C, sequence protocol

Brandon Craig Rhodes brandon at ten22.rhodesmill.org
Thu Sep 9 22:17:27 CEST 2004


Donn Cave <donn at u.washington.edu> writes:

> In article <chq9eg$c2i$1 at schleim.qwe.de>,

> 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])

Note, however, that this requires Python to create a list with the
values 1, 2, and 3 in it; then pass that value to your init function;
and finally discard the list when the initializer has completed.
Perhaps more efficient (maybe you could test both to compare the
expense?) would be for your initialization function to accept the new
sequence members as arguments themselves:

    m = myType(1, 2, 3)

This way a list does not have to be created and destroyed, with all
the associated computation, each time you initialize a myType.

-- 
Brandon Craig Rhodes   brandon at rhodesmill.org   http://rhodesmill.org/brandon



More information about the Python-list mailing list