"Michele Simionato" wrote:

> In this case I have used hasattr(obj, "__iter__") instead of
> isinstance(obj, list)
> (strings are iterable but do not have __iter__ method). I think hasattr
> is much better
> since it works for tuples and custom iterables too.

The fact that strings don't have __iter__ is an implementation detail
(I can't think of any reason other than historic and perhaps backwards
compatibility for this; iterables should IMHO by definition be exactly
the objects with __iter__). Also, what if tuples and any other
iterables except for lists are considered atomic ? An implementation of
s-expressions would use a single data structure for the nesting (e.g. a
builtin list or a custom linked list) and objects of all other types
should be considered atoms, even if they happen to be iterable.

George

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to