Nested class structures
Diez B. Roggisch
deetsNOSPAM at web.de
Sat Sep 11 11:05:42 EDT 2004
>> The only thing that comes to my mind is to create the classes from
>> strings you exec - that will allow you to captur the class before
>> redefining it:
>
> You can capture before redefining without any need to exec:
>
>>>> class outside:
> ... anons=[]
> ... class anon:
> ... def method1(self): return 'the first'
> ... anons.append(anon)
> ... class anon:
> ... def method1(self): return 'the second'
> ... anons.append(anon)
> ... class anon:
> ... def method1(self): return 'the third'
> ... anons.append(anon)
> ... del anon
Thats a nice one. I always forget about the possibility to execute actual
code while a class is encountered by the interpreter. As always, I'm
impressed on the variety of things doable in python - even if they don't
appeal to me as exactly useful (in this special case I mean.)
> No way! Classes as well as functions are perfectly fine objects.
> Python has no 'declarations'.
The reason I said that was because of the way the debugger steps through the
code: If it comes to a def, it doesn't execute the body - naturally. But it
collects of course the function as callable. That I viewed that as sort of
declaration - but you are of course right that there is no such thing as an
actual declaration in python.
--
Regards,
Diez B. Roggisch
More information about the Python-list
mailing list