[Tutor] flatten a tuple

Michael P. Reilly arcege@speakeasy.net
Fri, 20 Apr 2001 15:21:41 -0400 (EDT)


Bruce Sass wrote
> I'd say the best way is to do...
> 
>     ListType = type([])
>     ...
>     if type(L) == ListType
> 
> The first line is what "import types" does; doing it manually will
> always be faster because there is no "import" or attribute access
> (".") overhead.

Folks,

If you are concerned with this level of efficiency, then it is very
likely that you have a decent sized application, and that you are doing
this in a number of places.  Creating all these *Type values in a lot of
different modules is going to be far more wasteful (memory and speed)
than importing the types module.

And if you are so concerned with the attribute references, you can
use the "from types import ListType" form.  The time to load an already
compiled standard module is not all that much.

Except for small, pedantic scripts, defining your own ListType global
isn't more efficient at all, and probably the worst way to do this
(at least the `type([])' method frees the memory).

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |