Prothon gets Major Facelift in Vers 0.1.0 [Prothon]

gabor gabor at z10n.net
Mon May 24 05:09:07 EDT 2004


On Sun, 2004-05-23 at 21:46 +0000, Neil Hodgson wrote:
> gabor:
> 
> > hmmm...i understand that you can cast away const,
> > but what about...
> >
> > class C
> > {
> > private x;
> > };
> 
>    Technique 1:
> 
> class D {
> public:
>     int x;
> };
> 
>    C c;
>    (reinterpret_cast<D*>(&c))->x = 1;
> 
>    Technique 2:
> 
> #define private public
> #include <C_definition.h>
> #undef private
> 
>    C c;
>    c.x = 1;
> 
thanks...very interesting.

>    In both of these it is obvious that the encapsulation rules are being
> broken which is exactly the same situation as when someone uses the mangled
> name in Python. I have used technique 2 in production code where a library
> could not be altered and access to private methods was required.

look...i am not asking for a way in python to COMPLETELY RESTRICT the
access to a variable... i hint is enough... now...if i know correctly
that means that i have to prefix my wanto-to-be-private variables with a
"_"... that restriction would be enough for me. my problem is with the
syntax. i HATE anything that even remotely resembles perl/hungarian
notation. why cannot i do it somehow as we create static-methods ....

class C:
	def __init__(self):
		self.lenght = 5
		self.lenght =private(self.length)

or something like it.

the point is:
i only want to WRITE that the variable is private once...
i don't want to deal with _prefixed variables in my whole code...

this is imho of course

gabor





More information about the Python-list mailing list