nesting class definitions?
Martin von Loewis
loewis at informatik.hu-berlin.de
Fri Jan 28 15:35:34 EST 2000
Gerrit Holl <gerrit.holl at pobox.com> writes:
> Ah, but what I meant was:
>
> class Jan:
> class Piet:
> ...
> class Henk:
> ...
>
> Is there any point in using this feature?
I've seen it used in the Gnome libglade Python module, for
encapsulation reasons: The name started with __, so the only way to
create instances of this class was from inside methods of the outer
class (or by knowing how __ names are translated). I feel they should
have better used a module-scoped class, starting with an underscore
(so from libglade import * would not import it).
Another example is in the threading module's test() function, where
classes are nested inside functions; the same happens in copy._test.
profile.Profile has a nested class fake_code, again for hiding
purposes. Whether the use is justified is up to the reader.
Regards,
Martin
More information about the Python-list
mailing list