Re: Can my own objects support tuple unpacking?

2008-03-28 Thread greg
Scott David Daniels wrote: > class Foo(object): # _Never_ use old-style without a reason > def __getitem__(self, index): > print index > if index < 3: > return index * 5 # just to see > raise IndexError('Zapped') # The secret -- run

Re: Can my own objects support tuple unpacking?

2008-03-26 Thread Scott David Daniels
Patrick Toomey wrote: > ... I am trying to figure out how tuple unpacking behavior works > a,b,c,d = e > > Is a method called, such as __getitem__ for each index on the left > (0,1,2,3)? I thought this was logical, ... > > class Foo: > def __getitem__(self, index): > print index >

Can my own objects support tuple unpacking?

2008-03-26 Thread Patrick Toomey
Hello, So, I am new to python, but I always like to learn the ins and outs of a language by trying to understand how everything fits together. Anyway, I am trying to figure out how tuple unpacking behavior works. Specifically, what happens when I do the following: a,b,c,d = e Is a meth