Skip to main content
added 327 characters in body; deleted 5 characters in body
Source Link
Andrew Hare
  • 353.2k
  • 75
  • 649
  • 642

Python allows for private class members with the double underscore prefix. This technique doesn't work at a module level so I am thinking this is a mistake in Dive Into Python.

Here is an example of private class functions:

class foo():
    def bar(self): pass
    def __bar(self): pass
    
f = foo()
f.bar()   # this call succeeds
f.__bar() # this call fails

Python allows for private class members with the double underscore prefix.

Python allows for private class members with the double underscore prefix. This technique doesn't work at a module level so I am thinking this is a mistake in Dive Into Python.

Here is an example of private class functions:

class foo():
    def bar(self): pass
    def __bar(self): pass
    
f = foo()
f.bar()   # this call succeeds
f.__bar() # this call fails
Source Link
Andrew Hare
  • 353.2k
  • 75
  • 649
  • 642

Python allows for private class members with the double underscore prefix.