Skip to content

Instantly share code, notes, and snippets.

@hanksudo
Created October 8, 2017 16:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hanksudo/665dd3e24216068efae2f480fd6b56ac to your computer and use it in GitHub Desktop.
Save hanksudo/665dd3e24216068efae2f480fd6b56ac to your computer and use it in GitHub Desktop.
Python - class private publc
class Person:
def __init__(self):
pass
def _single(self):
print "single"
def __double(self):
print "double"
p = Person()
print(dir(p)) # ['_Person__double', '__doc__', '__init__', '__module__', '_single']
p._single() # single
p._Person__double() # double
p.__double() # AttributeError: Person instance has no attribute '__double'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment