Sequence-length - Missing the obvious ?
Michael Husmann
michael.husmann at teleatlas.com
Wed May 31 05:41:41 EDT 2000
python knows that you have passed a string. The same would
work with lists, tuples ... but not if you pass an integer.
HTH,
Michael
> considering the following code:
>
> -----------------------------------
>
> class sequence:
>
> def __getitem__( self, i ):
> return self.d[i]
>
> seq = sequence()
> seq.d = "Hallo"
>
> for item in seq:
> print item,
>
> -----------------------------------
>
> This works - gives out "H a l l o".
> __getitem__ get´s called five times.
>
> But why ? How does the for loop knows
> how much elements the sequence contains ?
> I did not program the __len__ function,
> so... how ?
>
> --
> --
> Regards & Gruesse from Mickey @ http://www.Vanille.de
> ---------------------------------------------------------
> How could anyone know me - when I don't even know myself ?
More information about the Python-list
mailing list