Python method to remove iterability

Posted by Debilski on Stack Overflow See other posts from Stack Overflow or by Debilski
Published on 2010-03-20T12:34:19Z Indexed on 2010/03/20 12:41 UTC
Read the original article Hit count: 215

Suppose I have a function which can either take an iterable/iterator or a non-iterable as an argument. Iterability is checked with try: iter(arg).

Depending whether the input is an iterable or not, the outcome of the method will be different. Not when I want to pass a non-iterable as iterable input, it is easy to do: I’ll just wrap it with a tuple.

What do I do when I want to pass an iterable (a string for example) but want the function to take it as if it’s non-iterable? E.g. make that iter(str) fails.

© Stack Overflow or respective owner

Related posts about python

Related posts about iterator