private
Bjorn Pettersen
BPettersen at NAREX.com
Mon Jul 1 00:57:16 EDT 2002
> From: - c o v e n t r y -
>
> >>Kind of off-topic, but this got me curious. The only way I
> >>could think of is to assume (which I think is always true)
> >>that the private data members are in order from the starting
> >>address so based on the offset from the address of the object
> >>you could access each one.
> >>
> >
> > .. and of course #define private public, or just go in and
> edit the .h
> > file...
>
> True, but you could edit gcc to allow access to private
> members of a C++
> class, could you not? Hrm, this issue probably isn't whether it is
> possible to hack around an implementation of 'private', but
> more about having a real 'private' type/functionality. Right
> now, we hack to put simulate private - why not make other
> hack to work around it?
The OP asked about private vars/methods like C++. Above are three ways
to get around private in C++ without recompiling the (possibly third
party) C++ library you're #including. As you see, the private
declaration in C++ is mostly informational. In Python we use _ or __
prepended to var/method names to achieve the same effect. Python does
have true private vars/methods through the Bastion module, but most
Pythonistas don't see the purpose. After all, if you can't trust your
developers you have bigger problems.
-- bjorn
More information about the Python-list
mailing list