Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80861

isiter builtin

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin3!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <googberg@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.027
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; 'python.': 0.02; 'builtin': 0.09; 'url:github': 0.09; 'python': 0.11; 'checking,': 0.16; 'hasattr(obj,': 0.16; 'iterated': 0.16; 'iterator': 0.16; 'iterators': 0.16; 'rarely': 0.16; 'input': 0.22; 'bytes': 0.24; 'propose': 0.24; 'asking': 0.27; 'function': 0.29; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; 'checking': 0.33; 'created': 0.35; 'problem.': 0.35; 'something': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'returning': 0.36; 'two': 0.37; 'to:addr:python-list': 0.38; 'fact': 0.38; 'that,': 0.38; 'use.': 0.39; 'to:addr:python.org': 0.39; 'most': 0.60; 'new': 0.61; 'simple': 0.61; 'here:': 0.62; 'times': 0.62; 'address': 0.63; 'great': 0.65; 'determine': 0.67
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=h6EjA180qlhtlwYF0GtGBqvSKf8VGhoXVDk/DIj9f74=; b=JWTfDx6xtLVd7D19LwEvUZiqQL6BwTg5Gdb4xhKQXL737P97X8TxHSYAwpUm9i96eT JAX0Kw45QRb2BRjXBNuh07kbg9eWacBdjn3TQ7Uk6HwssO1CNs6pXdVh0ng31KkkFqCK Hj/ssZu7J6ZBMFjNFKv7z6vMMsWWRqsBfWhXI2vlZJVMtraxa+y+c2NyVrR2meq/uivl tHAnqBUyt/yLgmm7HPuQmiQHe4tea4HolCuMvbEuJgCE5Ykp8ihX/K1OlA4z+T4vnmSi hpbLaVUxMTOTETp74UrOdOZDZy+Xu3dYZIbs9N2WpvYuKksDkQFwpt5bhUVZfjyr/N4d rxgg==
X-Received by 10.112.219.3 with SMTP id pk3mr18356378lbc.18.1416124668223; Sat, 15 Nov 2014 23:57:48 -0800 (PST)
MIME-Version 1.0
From Garrett Berg <googberg@gmail.com>
Date Sun, 16 Nov 2014 00:57:27 -0700
Subject isiter builtin
To python-list@python.org
Content-Type multipart/alternative; boundary=001a11c3d9facea6f30507f5379c
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.15874.1416124670.18130.python-list@python.org> (permalink)
Lines 57
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1416124670 news.xs4all.nl 2839 [2001:888:2000:d::a6]:53088
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:80861

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

I have been working with python for a few years now, and two of my favorite
features about it are iterators and duck typing. The fact that every
iterator under the sun can be accessed with a simple for loop is one of the
most amazing features of python.

However, there are times when I want to do type checking, and the builtin
function *isinstance* is of great use. However, this function fails to be
satisfactory in returning whether the object is a valid iterator. The call
hasattr(obj, '__iter__') also fails because str and bytes types both have
that, and are rarely what you mean when you are asking if something is an
iterator (how often have you iterated over a string?)

I propose a new builtin to address this problem. I have created code for it
here:

https://gist.github.com/cloudformdesign/de9b54d30547ddd28ec4

This will allow simple type checking on an input to determine whether it is
an iterator.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

isiter builtin Garrett Berg <googberg@gmail.com> - 2014-11-16 00:57 -0700

csiph-web