itertools.flatten()? and copying generators/iterators.

Alex Martelli aleax at aleax.it
Tue Oct 28 09:40:46 EST 2003


Francis Avila wrote:
   ...
> try: seq+'' seems more expensive.  Is it just to handle the case where
> someone makes a string-alike that doesn't derive from str? (Actually, I

As per my other post, it sure SEEMS more expensive - whether it IS or
not depends on details:-).  Yes, it's basically to try and treat as a
string any class that looks like one.

> guess that's about all pre-2.2 code.)

Nope, UserString is still alive and well in 2.2 and 2.3 -- and doesn't
subclass basestring (I don't know why).  Yes, if you write stringlike
classes in 2.2 and later, subclassing basestring, just as a "flag" since
quite a few spots may specialcase instances of basestring, IS becoming
advisable, I suspect.

> Is it expensive enough to even matter?

Nope (in the sample case I measured), again see my other post for
details.  But perhaps my old-style insistence against isinstance
abuse is becoming misplaced in this one case -- basestring exists
ONLY for the purpose of allowing easy isinstance checks, after all,
it offers no useful functionality per se.  So, I should maybe
resign myself to the inevitable...

...and hope a similar type 'basenumber' to become the "just flagging"
baseclass of int, long, float and complext doesn't emerge...:-)


Alex





More information about the Python-list mailing list