[issue19441] itertools.tee improve documentation

New submission from Alan Cristhian: I had some problems using itertools.tee function. Fortunately I found the following advice on the PEP-323: "Currently, the copied iterators remaintied to the original iterator. If the original advances, then so do all of the copies. Good practice is to overwrite the original So THAT anamolies do result: a, b = t (a)." I believe that such advice should be in the documentation as well: "Currently, the copied iterators remaintied to the original iterator. If the original advances, then so do all of the copies and vice versa. Good practice is to overwrite the original So THAT anamolies do result: a, b = t (a ). " Note that I added "and vice versa". ---------- assignee: docs@python components: Documentation messages: 201693 nosy: Alan.Cristhian, docs@python priority: normal severity: normal status: open title: itertools.tee improve documentation type: enhancement versions: Python 3.3 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue19441> _______________________________________

Changes by Raymond Hettinger <raymond.hettinger@gmail.com>: ---------- assignee: docs@python -> rhettinger nosy: +rhettinger _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue19441> _______________________________________

Raymond Hettinger added the comment: I don't want to recommend overwriting the variable name but will add a note for the rest: "Copied iterators depend the original iterator. If the original advances, then so do the copies. After teeing the iterators, the usual practice is to stop working with the original iterator and operate only on the new tee-ed iterators." FWIW, the situation is analogous to str.upper(). We note that string methods produce new strings. We don't state that a best practice is to overwrite the variable with "s = s.upper()". That is sometimes what you want and sometimes not. ---------- priority: normal -> low _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue19441> _______________________________________

Alan Cristhian added the comment: Ok, I agree. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue19441> _______________________________________

Raymond Hettinger <raymond.hettinger@gmail.com> added the comment: This is out of date. The docs currently have: ''' Once :func:`tee` has made a split, the original *iterable* should not be used anywhere else; otherwise, the *iterable* could get advanced without the tee objects being informed. ''' ---------- resolution: -> out of date stage: -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue19441> _______________________________________
participants (2)
-
Alan Cristhian
-
Raymond Hettinger