Will python never intend to support private, protected and public?

Paul Rubin http
Fri Sep 30 07:43:00 EDT 2005


Steven D'Aprano <steve at REMOVETHIScyber.com.au> writes:
> > 2) Allow the client access to these private variables, through
> > a special construct. Maybe instead of "from ... import ..."
> > "from ... spy ...".
> 
> What you are suggesting is that you have private variables that are only
> private by convention, since anyone can simply call use spy to treat
> them as public.

This notion isn't so bad, if there's way for modules to notice when
they're spied on, like an import hook, e.g.:

  def __spy__(othermodule, symbol_list):
     # this gets called when another module spies on symbols

It's like a runtime version of C++'s "friend" declaration.  Well, not
quite as good, it's like having some stranger slide over to you in a
bar and say "I wanna be your friend".  But at least it's better than
not finding out at all where the external references are.



More information about the Python-list mailing list