Python Productivity over C++
Thomas Wouters
thomas at xs4all.net
Thu Jun 15 14:05:57 EDT 2000
On Thu, Jun 15, 2000 at 07:50:14PM +0200, Michal Vitecek wrote:
[ access control ]
> >Look at the big picture. Do encapsulation, access control and type
> >strictness really make C++ really less error prone than python?
> >I think not.
> but what are the method names with '_' at the beginning in modules for?
> aren't they there as a kind of hack to implement some way of access
> control?
No, they are a form of reducing namespace clutter and name-clashing.
Variable names starting with a '_' do not get imported into the local
namespace when you use 'from <module> import *'. They are accessible just
fine, they just do not get bound to a *local* (to the 'from module import'
statement) name.
Class variables (including methods) starting with a double _ get 'mangled'
to make them private -- so you can store 'class-related' data without the
risk of a subclass accidentily shadowing it. The class-related data is still
very accessible, it's perfectly valid to say 'self._BaseClass__private_data'
or some such.
--
Thomas Wouters <thomas at xs4all.net>
Hi! I'm a .signature virus! copy me into your .signature file to help me spread!
More information about the Python-list
mailing list