(self, tree)
Generate and save tree code to file
        :param tree:
        :return:
Generate and save tree code to file
        :param tree:
        :return:
Generate and save tree code to file : param tree : : return :
def save_tree(self, tree):
        """
        Generate and save tree code to file
        :param tree:
        :return:
        """
        signs = []
        tree_code = ""

        def get_code_tree(T):
            nonlocal tree_code
            if T.sign is not None:
                signs.append(T.sign)
            if T.left:
                tree_code += "0"
                get_code_tree(T.left)
            if T.right:
                tree_code += "1"
                get_code_tree(T.right)

        get_code_tree(tree)
        self.write_bits(tree_code + "1")  # "1" indicates that tree ended (it will be needed to load the tree)
        for int_sign in signs:
            self.write_int(int_sign)
def save_tree ( self , tree ) : signs = [ ] tree_code = "" def get_code_tree ( T ) : nonlocal tree_code if T . sign is not None : signs . append ( T . sign ) if T . left : tree_code += "0" get_code_tree ( T . left ) if T . right : tree_code += "1" get_code_tree ( T . right ) get_code_tree ( tree ) self . write_bits ( tree_code + "1" ) # "1" indicates that tree ended (it will be needed to load the tree) for int_sign in signs : self . write_int ( int_sign )