Ještě mě napadlo, že by se na to dalo jít takto: class Seznam:
def __init__(self, sez): self.data = sez def __getitem__(self, idx): if isinstance(idx, slice): return self._slice(idx.start, idx.stop, idx.step) return self.data[idx] if idx < len(self.data) else None def _slice(self, start, stop, step): if step is None: step = 1 for i in range(start, stop, step): yield self[i] slova = Seznam(("item1", "item2")) a, b, c, d = slova[:4] assert (a, b, c, d) == ("item1", "item2", None, None) # projde to PM 2010/4/20 Petr Messner <petr.mess...@gmail.com>: > Problem ale stejne bude v tom, ze kdyz chci > > prvy, druhy, treti, ctrty = slova > > tak ten iterator musi vratit presne 4 hodnoty a pak vyvolat > StopIteration. A jak tomu reknes, ze z toho tahas ty 4 hodnoty? Leda > tak tim, ze tam fakt budou presne 4. To ale neni chovani, ktere > ocekava tazatel. > > viz http://docs.python.org/reference/simple_stmts.html#assignment-statements > - "If the target list is a comma-separated list of targets: The object > must be an iterable with the same number of items as there are targets > in the target list," > > PM > _______________________________________________ Python mailing list Python@py.cz http://www.py.cz/mailman/listinfo/python