I recently posted a stackoverflow question and got permission.
Someone offered me a coding style, and I did not get any additional input. I have the following question with a link to a previous request.
How can we declare private variables inside a class in python? I thought using double underscore (__) to treat a variable as confidential. Please correct me.
As suggested earlier, we don’t need to use the getter or setter method. Shouldn't we use a getter or setter, or both? Please let me know your suggestion about this.
Python public, __ - , , .
public
__
, , public , .
Idiomatic Python get/set accessors, , private.
private
, -, , - __ .
, , -, , , , , , Python 20 , .
PEP 8 (http://www.python.org/dev/peps/pep-0008/) " ", .
:
" "private", Python ( ).
" , , ."
, .
Update:
(, ). - . - python pythonic.
Python getters seters. - , , .
http://adam.gomaa.us/blog/2008/aug/11/the-python-property-builtin/
, , python. , , . "".
Getter/:
, , 'private'. , , . , getter/setter.
1) http://docs.python.org/tutorial/classes.html#private-variables
"Private" , , , Python. , , Python: (, _spam) API ( , ), .
( )
2) http://docs.python.org/library/functions.html#property