Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #37107 > unrolled thread

To make a method or attribute private

Started byiMath <redstone-cold@163.com>
First post2013-01-20 01:17 -0800
Last post2013-01-20 21:45 -0500
Articles 6 — 5 participants

Back to article view | Back to comp.lang.python


Contents

  To make a method or attribute private iMath <redstone-cold@163.com> - 2013-01-20 01:17 -0800
    Re: To make a method or attribute private Chris Angelico <rosuav@gmail.com> - 2013-01-20 20:23 +1100
      Re: To make a method or attribute private alex23 <wuwei23@gmail.com> - 2013-01-20 15:14 -0800
        Re: To make a method or attribute private Dave Angel <d@davea.name> - 2013-01-20 18:32 -0500
          Re: To make a method or attribute private alex23 <wuwei23@gmail.com> - 2013-01-20 18:24 -0800
            Re: To make a method or attribute private Mitya Sirenef <msirenef@lightbird.net> - 2013-01-20 21:45 -0500

#37107 — To make a method or attribute private

FromiMath <redstone-cold@163.com>
Date2013-01-20 01:17 -0800
SubjectTo make a method or attribute private
Message-ID<8adf7e6a-e16a-4d81-8e0d-6339bb4f117c@googlegroups.com>
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 .

>>> class A:
...     def __init__(self):
...         self.a = 'a'
...         self._a = '_a'
...         self.__a = '__a'
...



>>> ap = A()
>>> ap.a
'a'
>>> ap._a
'_a'
>>> ap.__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 methods or attributes?

[toc] | [next] | [standalone]


#37108

FromChris Angelico <rosuav@gmail.com>
Date2013-01-20 20:23 +1100
Message-ID<mailman.703.1358673801.2939.python-list@python.org>
In reply to#37107
On Sun, Jan 20, 2013 at 8:17 PM, iMath <redstone-cold@163.com> wrote:
> so what is your opinion about single leading underscore and private methods or attributes?

Didn't this get discussed recently?

http://mail.python.org/pipermail/python-list/2013-January/638687.html

ChrisA

[toc] | [prev] | [next] | [standalone]


#37124

Fromalex23 <wuwei23@gmail.com>
Date2013-01-20 15:14 -0800
Message-ID<350446de-b601-4ff8-96e4-9f9a5674c48e@sb6g2000pbb.googlegroups.com>
In reply to#37108
On Jan 20, 7:23 pm, Chris Angelico <ros...@gmail.com> wrote:
> On Sun, Jan 20, 2013 at 8:17 PM, iMath <redstone-c...@163.com> wrote:
> > so what is your opinion about single leading underscore and private methods or attributes?
>
> Didn't this get discussed recently?
>
> http://mail.python.org/pipermail/python-list/2013-January/638687.html
>
> ChrisA

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

[toc] | [prev] | [next] | [standalone]


#37125

FromDave Angel <d@davea.name>
Date2013-01-20 18:32 -0500
Message-ID<mailman.711.1358724796.2939.python-list@python.org>
In reply to#37124
On 01/20/2013 06:14 PM, alex23 wrote:
> On Jan 20, 7:23 pm, Chris Angelico <ros...@gmail.com> wrote:
>> On Sun, Jan 20, 2013 at 8:17 PM, iMath <redstone-c...@163.com> wrote:
>>> so what is your opinion about single leading underscore and private methods or attributes?
>>
>> Didn't this get discussed recently?
>>
>> http://mail.python.org/pipermail/python-list/2013-January/638687.html
>>
>> ChrisA
>
> 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.


-- 
DaveA

[toc] | [prev] | [next] | [standalone]


#37135

Fromalex23 <wuwei23@gmail.com>
Date2013-01-20 18:24 -0800
Message-ID<5a502e5a-9912-4584-bcad-4c00ca350da5@qi8g2000pbb.googlegroups.com>
In reply to#37125
On Jan 21, 9:32 am, Dave Angel <d...@davea.name> wrote:
> On 01/20/2013 06:14 PM, alex23 wrote:
>
> > On Jan 20, 7:23 pm, Chris Angelico <ros...@gmail.com> wrote:
> >> On Sun, Jan 20, 2013 at 8:17 PM, iMath <redstone-c...@163.com> wrote:
> >>> so what is your opinion about single leading underscore and private methods or attributes?
>
> >> Didn't this get discussed recently?
>
> >>http://mail.python.org/pipermail/python-list/2013-January/638687.html
>
> >> ChrisA
>
> > 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.

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?

[toc] | [prev] | [next] | [standalone]


#37136

FromMitya Sirenef <msirenef@lightbird.net>
Date2013-01-20 21:45 -0500
Message-ID<mailman.716.1358736304.2939.python-list@python.org>
In reply to#37135
On 01/20/2013 09:24 PM, alex23 wrote:
> On Jan 21, 9:32 am, Dave Angel  <d...@davea.name> wrote:
 >> On 01/20/2013 06:14 PM, alex23 wrote:
 >>
 >>> On Jan 20, 7:23 pm, Chris Angelico <ros...@gmail.com> wrote:
 >>>> On Sun, Jan 20, 2013 at 8:17 PM, iMath <redstone-c...@163.com> wrote:
 >>>>> so what is your opinion about single leading underscore and 
private methods or attributes?
 >>
 >>>> Didn't this get discussed recently?
 >>
 >>>> http://mail.python.org/pipermail/python-list/2013-January/638687.html
 >>
 >>>> ChrisA
 >>
 >>> 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.
 >
 > 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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web