just for fun: make a class (not its instances) iterable

Terry Reedy tjreedy at udel.edu
Wed Aug 10 02:11:29 CEST 2011


On 8/9/2011 5:43 PM, Gelonida N wrote:
> Now I wondered whether there is any way to  implement a class such, that
> I can write
>
> for val in MyClass:
> 	print val

And what are the items in a class that you expect that to produce?

I am pretty sure you can already do
for val in MyClass.__dict__

(or __dict__.items())

-- 
Terry Jan Reedy




More information about the Python-list mailing list