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


Groups > comp.lang.python > #80861 > unrolled thread

isiter builtin

Started byGarrett Berg <googberg@gmail.com>
First post2014-11-16 00:57 -0700
Last post2014-11-16 00:57 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

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

#80861 — isiter builtin

FromGarrett Berg <googberg@gmail.com>
Date2014-11-16 00:57 -0700
Subjectisiter builtin
Message-ID<mailman.15874.1416124670.18130.python-list@python.org>

[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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web