[Tutor] flatten a tuple

Bruce Sass bsass@freenet.edmonton.ab.ca
Fri, 20 Apr 2001 15:26:52 -0600 (MDT)


On Fri, 20 Apr 2001, Michael P. Reilly wrote:

> 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.

Ya, there is no "best way" in the general case...

> 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).

...this was for a standalone script with a single check inside a loop.

Thanks for the reality check though,
it is easy to get hooked on one way of doing things.

Two questions come to mind:

Why isn't this a FAQ?

Anyone have any idea of how many manual someType=type(something)-s are
in an "import types".  ``grep "Type = type(" types.py | wc -l'' -> 28
with py-2.1, so does that mean you could do it manually >28 times
before using "import types" is more efficient?


- Bruce