__all__ in classes?
Terry Reedy
tjreedy at udel.edu
Thu Jan 16 15:56:28 EST 2003
"Magnus Lie Hetland" <mlh at furu.idi.ntnu.no> wrote in message
news:slrnb2e3kb.gp8.mlh at furu.idi.ntnu.no...
> I just had an idea: Perhaps the following could be a useful
convention
> for private attributes (and methods)?
>
> >>> class Foo:
> ... __all__ = 'bar', 'baz'
> ... bar = 42
> ... frozz = 51
> ... def baz(self):
> ... return 42
> >>> f = Foo()
> >>> f.bar
> 42
> >>> f.baz()
> 42
> >>> f.frozz
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> AttributeError: Foo attribute 'frozz' is private
Note that __all__ in modules does not work this way. It only controls
what is exported as *, not what is accessible.
TJR
More information about the Python-list
mailing list