private variables/methods

Harri Pesonen fuerte at sci.fi
Fri Oct 10 15:16:36 EDT 2003


Peter Hansen wrote:
> gabor wrote:
> 
>>On Thu, 2003-10-09 at 10:12, Dave Benjamin wrote:
>>
>>>In article <mailman.1065685337.1770.python-list at python.org>, gabor wrote:
>>>
>>>>as far as i know in python there aren't any private (i mean not accessible
>>>>from the outside of the object) methods/fields.
>>>>
>>>>why?
>>>
>>>No offense, but this is like the 4000th time someone has asked that question
>>>here. Could you try searching Google groups first?
>>
>>you're right, i'm sorry.
>>
>>after reading the archives:
>>
>>i think i didn't express myself too well.
>>i'll try again:
> 
> Don't bother.  You perhaps didn't really read enough of the archives,
> because Dave's point still stands.  None of your questions or comments, 
> as far as I can tell, ask or say anything that hasn't already been
> asked (and answered) or said before.

Because it has been asked 4000 times probably means that there is a 
great need for the feature...

> In summary: it's more of a philosophical difference than anything, and
> Python simply doesn't *want* a "private" keyword, nor things like that
> which artificially restrict the programmer.  (Again, even that comment
> adds nothing new, so you're really wasting your and our time by responding
> rather than continuing to read the zillion old threads on the topic.)

"Python" doesn't want a "private" keyword? I have quite a limited Python 
experience but I would like to have the following features in Python 
that are common in other languages:

* Option Explicit
* variable type declaration (optional)
* private variables/methods

Most of these are handy for large projects, where you want to be sure 
that a class is not misused (by other developers). These also mean that 
it is much harder to create bugs. I like Python a lot, but with these 
features it would be much better for serious development of complex 
applications, not just for scripting.

One thing I have noticed that the keyword "global" is very confusing. 
For example, the following is syntactically valid Python:

a = 1
def b():
	a = 2
def c():
	return a

But it does not work as expected. Function b just creates a new local 
variable "a" inside function b! The correct function is of course:

def b():
	global a
	a = 2

On the other hand, function c refers to the same global variable just 
fine without any extra "global" keyword. Why on earth?? :-) In every 
other language I know you don't need "global". It is ugly.

Harri





More information about the Python-list mailing list