PI. Data hidding

Run Settings
LanguagePython
Language Version
Run Command
import json # Lets exercise our power to hide data inside class instances. class Hidden: def __init__(self): # This is the general syntax to create public attributes, no underscores # at the begining of it's name makes it totaly public. self.public = True # There's a verbal agreement that all attributes that starts with one # underscore are become protected. But it is not supporting on the # language level, so if you want you still can access them, but since # then you're the one responsible for all troubles. self._protected = "Still have an access" # And finally here's the way to make provate attributes and even on # language level they are kind a provate... Lets take a look. self.__private = "Hard to find" h = Hidden() print "Public: {0}".format(h.public) print "Protected: {0}".format(h._protected) # We can access to private variable only using specific syntax. It's definitely # not portable, so better not use it. print "Private: {0}".format(h._Hidden__private) # And surely all of them is observable here. print json.dumps(h.__dict__, indent=4)
Editor Settings
Theme
Key bindings
Full width
Lines