<jupyter_start><jupyter_text>Item 27 Prefer Public Attributes over Private Ones There are public and private attibures in Python. Private attributes raise exceptions when trying to access them.<jupyter_code>class Test:
    def __init__(self):
        self.a = 10 # public
        self._a = 15 # Not private, just an notation from PEP8 --> protected
        self.__a = 20 # Actually private
a = Test()
a.a
a._a
a.__a<jupyter_output><empty_output><jupyter_text>You can stil access them. Using double underlines just transforms the name.<jupyter_code>a.__dict__
a._Test__a<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07846410684474124, 'fraction_numerical': 0.015025041736227046, 'mean_word_length': 4.357142857142857, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '281211', 'license': 'MIT', 'n_tokens_mistral': 195, 'n_tokens_neox': 185, 'n_words': 62, 'path': 'notes/Chapter_3:_Classes_and_Inheritance/Item 27 Prefer Public Attributes over Private Ones.ipynb', 'repo_name': 'johannstruongle/effective_python', 'size': '599'}