To make a method or attribute private

I

iMath

To make a method or attribute private (inaccessible from the outside), simply start its
name with two underscores

----《Beginning Python From Novice to Professional》

but there is another saying goes:
Beginning a variable name with a single underscore indicates that the variable should be treated as ‘private’.

I test both these 2 rules ,it seems only names that start with two underscores are REAL private methods or attributes .
.... def __init__(self):
.... self.a = 'a'
.... self._a = '_a'
.... self.__a = '__a'
....


Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: A instance has no attribute '__a'

so what is your opinion about single leading underscore and private methodsor attributes?
 
D

Dave Angel

Isn't that a link to the same post that started this thread? :)

No, that's the one that started the earlier thread, by the same name,
three whole days ago. iMath posted an apparently complete duplicate of
his earlier message.
 
A

alex23

No, that's the one that started the earlier thread, by the same name,
three whole days ago.  iMath posted an apparently complete duplicateof
his earlier message.

The link is to a post of the same date as the original of this thread,
and the very first response is mine, same as with this thread. I'm
still not seeing the dupe?
 
M

Mitya Sirenef

The link is to a post of the same date as the original of this thread,
and the very first response is mine, same as with this thread. I'm
still not seeing the dupe?

I do see the duplicate in my reader.. -m


--
Lark's Tongue Guide to Python: http://lightbird.net/larks/

To knock a thing down, especially if it is cocked at an arrogant angle, is
a deep delight of the blood.
George Santayana
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top