Question

I'm building an SQL query's Regex, which I'm passing to a Python function. Here's what I'm currently doing (iterable is a variable passed to the function):

if isinstance(iterable, (list, tuple, set)):
    app = '|'.join(iterable)

I'd like to be able to test for an abstraction (see the collection module's ABC's) that means that it's a container, but not a basestring. (which is iterable!)

Is there a way to improve on the above?

Was it helpful?

Solution

I don't think any such thing exists - what you have may be the best.

Occasionally, I have functions that take either strings (which i'll split) or an iterable of strings. For those, I usually go for a negative test instead i.e.

if isinstance(iterable, basestring):
    iterable = iterable.split(',')

etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top