Initializing a list with copies

Alex Martelli aleax at aleax.it
Tue Apr 30 11:58:53 EDT 2002


Thomas Heller wrote:

> "Alex Martelli" <aleax at aleax.it> wrote in message
> news:vIxz8.81546$vF6.2424489 at news2.tin.it...
>> Ralf Juengling wrote:
>>         ...
>> > BTW: It is not easy to add __iter__ to list's meta-type, is it?
>>
>> list's "metatype" (metaclass) is the built-in type named 'type'.
>> like for all other built-in types and new-style classes.  Adding
>> __iter__ to type would thus make almost 'everything' iterable.
>>
> Correction: adding __iter__ to type would make instances of
> type iterable (these things are normally called 'classes').

Classes (new-style) and built-in types, as I said.  Maybe I wasn't
as clear as needed to express once again the distinction between
levels -- instances of a metaclass are types (classes), so thanks
for pointing it out.

> Not too useful, it seems.

Particularly given that any class or type (or other callable) that
is callable without arguments can be used, in the same was as
Ralg, the OP, wanted to use an "iterable list", by passing it
in as the first argument to the two-argument form of iter.  The
second arg need only be any object that is sure to differ from
what calling the class/type/other callable can result in, to
ensure the resulting iterator is unbounded.


Alex




More information about the Python-list mailing list