Implicit lists

Alex Martelli aleax at
Thu Jan 30 18:23:54 CET 2003

On Thursday 30 January 2003 06:00 pm, holger krekel wrote:
> > Alas, doesn't meet specs...:
> I presume you refer to this part
> [dale]
>     In other words, I want to be able to treat an argument of arbitrary
>     type as a list of 1 if it isn't already a list.
> which isn't an overly explicit specification.  In particular,
> it doesn't imply that strings are to be excluded.

It says that strings are to be treated as a list of 1.  Not sure what
you mean by "excluded".  The OP also gave an example that did
not meet his own specs (he went out of his way to treat _tuples_
NOT as lists of one item).

> But i agree that grouping into 'non-iterables except strings and
> unicode' on one side and everything else on the other side most
> often makes sense.

Yes, as long as you also include "instances of UserString and
the like" among "strings and unicode".  Personally, I prefer to
talk of "string-like objects", and my favourite way to check if
an object is string-like is to see if thatobject+'' raises an
exception -- if it doesn't, it's stringlike enough for me.


More information about the Python-list mailing list