-1

What is good practice way of data hiding in python ? Is it the same as java ? private is with double underscore ? protected is with single underscore ? public function is possible, member public is not recommended ? Right ?

Alex
  • 33
  • 6
  • https://stackoverflow.com/questions/70528/why-are-pythons-private-methods-not-actually-private – Joe Sep 26 '18 at 11:06
  • https://mail.python.org/pipermail/tutor/2003-October/025932.html – Joe Sep 26 '18 at 11:06
  • https://stackoverflow.com/questions/15047122/python-private-function-coding-convention/15072306 – haklir Sep 26 '18 at 11:07
  • Perl culture is like python in this respect, but Perl expresses the sentiment a bit differently. As the Camel book puts it, `a Perl module would prefer that you stayed out of its living room because you weren't invited, not because it has a shotgun.` (from link in comment above) – Joe Sep 26 '18 at 11:19

1 Answers1

1

The concept of data hiding does not really exist in python.

From the docs:

“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.

Sharku
  • 1,052
  • 1
  • 11
  • 24