length - Missing the obvious ?
Michael Husmann
michael.husmann at teleatlas.com
Wed May 31 05:41:41 EDT 2000
More information about the Python-list mailing list
Wed May 31 05:41:41 EDT 2000
- Previous message (by thread): Sequence-length - Missing the obvious ?
- Next message (by thread): Subclass List
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 ?
- Previous message (by thread): Sequence-length - Missing the obvious ?
- Next message (by thread): Subclass List
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list