0

I'm using pydev with eclipse helios. From this link I can see that the yellow diamond indicates a protected member... in java. What does this mean in my pydev outline?

For the record, the once with circles are initialized as none e.g. self.id = None while the two with diamonds are initialized using an object factory self.object = object_factory(stuff in here)enter image description here

Community
  • 1
  • 1
Mitch
  • 1,604
  • 4
  • 20
  • 36

3 Answers3

1

In Python by convention an "_" means protected. And two "__" means private. The following is an image with both of cases:

enter image description here

So, in PyDev that diamond means the same that in Java. A protected member.

Here you have a good explanation about the subject.

Community
  • 1
  • 1
Raydel Miranda
  • 13,825
  • 3
  • 38
  • 60
0

Private members of the class. All members/methods in python are implicitly public. By doing _name we declare them private. So Eclipse is showing them as a special type in Outline view.

Mladen Uzelac
  • 1,173
  • 1
  • 10
  • 14
  • Yep, reproduced that. I suppose that does make sense, I just got hung up on python not having 'true' private members. Additionally it looks like prefacing with 2 underscores makes the same symbol as private for Java – Mitch Nov 18 '14 at 19:47
  • There a lot of stuff different in Python. It takes time to get used to. – Mladen Uzelac Nov 18 '14 at 19:48
  • The diamond don't means private members of the class. – Raydel Miranda Nov 18 '14 at 20:10
  • `“Private” instance variables that cannot be accessed except from inside an object don’t exist in Python. However, there is a convention that is followed by most Python code: a name prefixed with an underscore (e.g. _spam) should be treated as a non-public part of the API (whether it is a function, a method or a data member). It should be considered an implementation detail and subject to change without notice.` Is from Python documentation (https://docs.python.org/2/tutorial/classes.html#tut-private) So: _ is private instance variables, __ is private class variables. – Mladen Uzelac Nov 18 '14 at 20:32
-1

I see the two with the diamond begin with an underscore ("_"). While not enforced, this is a sign that the member fields are 'private' and should not be accessed by the user of the class.

See https://docs.python.org/2/tutorial/classes.html#tut-private for more details.

  • No private, protected. See my answer. – Raydel Miranda Nov 18 '14 at 20:44
  • Hence the apostrophes. There is no conecpt of 'private' or 'protected' variables in Python; you can force it to mangle the name by using a double underscore prefix, but you can still access and use that particular mangled member in your code. – Shkodran Gerguri Nov 18 '14 at 20:47
  • Your answer should say 'protected' not 'private'. There is no concept of `private` or `protected` in Python, however there is a convention: `_` stands for 'protected' while `__` for 'private'. And is true `__` forces a mangled name while `_` don't. That's why is "harder" to access directly to a `__` member than to a `_`. – Raydel Miranda Nov 18 '14 at 20:58