Q:

convert tree to string which contains only the leafs

I am looking for an algorithm which converts my binary tree structure: from my own class which where every node has a node.value, node.leftChild and node.rightChild. I want to convert this tree to the Newick format so only the leafs and the structure of the tree must be converted.
a tree likeenter image description here must become (B,(E,F)) (so without the internal nodes)
I think the best way is to travers my tree recursively and build the string but I always have errors for particular trees.   
class binarynode(object):
def __init__(self, value, left = None, right = None,parent =None):
    self.parent = parent
    self.value = value
    self.left = left
    self.right = right

def isleaf(self):
    return ((self.right == None) and (self.left ==None))

def convertTReeAux(self):
    printValue = str(self.value)

    if (self.isleaf() and self.parent == None):
        ret = '('+printValue+')'

    elif (self.isleaf() and (self.parent.left.value == self.value)  and (self.parent.right.isleaf())) :
        ret = '('+str(printValue)+','

    elif (self.isleaf() and self.parent.right.value==self.value and self.parent.left.isleaf() and self.parent.parent !=None and self.parent.parent.right == self.parent):
        ret = str(printValue)+'))'

    elif (self.isleaf() and self.parent.right.value==self.value and self.parent.left.isleaf()):
        ret = str(printValue)+')'

    elif (self.isleaf() and (self.parent.left.value == self.value) and (not self.parent.right.isleaf())):
        ret = '('+str(printValue)+','

    elif (self.isleaf()  and self.parent.right.value ==self.value and (not self.parent.left.isleaf())):
        ret = ','+str(printValue)+')'

    elif( (not self.isleaf()) and (self.parent!= None) and (self.parent.left == self) and (not self.parent.right.isleaf())):
        ret = ""

    elif( (not self.isleaf()) and (self.parent!= None) and (self.parent.right ==self) and (not self.parent.left.isleaf())):
        ret="),"

    elif((not self.isleaf()) and (self.parent!= None) and (self.parent.left ==self) and (not self.parent.left.isleaf())):
        ret="("

    else:
        ret = ''

    if(self.left != None):
        ret += (self.left.convertTReeAux())
    if(self.right != None):
        ret += (self.right.convertTReeAux())
    return ret

A:

I think the following code is what you want. In the class Node, I defined function isLeaf() to check the node is leaf or not. 
class Node:
    value = ""
    leftChild = None
    rightChild = None
    def __init__(self, parent):
        self.parent = parent
    def isLeaf(self):
        if (self.leftChild == None and self.rightChild == None):
            return True
        else:
            return False

def convertTreeAux(node, newick):
    if node.isLeaf():
        newick.append(node.value)
    if node.leftChild != None:
        newick.append("(")
        convertTreeAux(node.leftChild, newick)
        newick.append(",")
    if node.rightChild != None:
        convertTreeAux(node.rightChild, newick)
        newick.append(")")

tree =  Node(None)
tree.value = "A"
tree.leftChild = Node(tree)
tree.leftChild.value = "B"
tree.rightChild = Node(tree)
tree.rightChild.value = "C"
tree.rightChild.leftChild = Node(tree.rightChild)
tree.rightChild.leftChild.value = "E"
tree.rightChild.rightChild = Node(tree.rightChild)
tree.rightChild.rightChild.value = "F"

newick = [] 
convertTreeAux(tree, newick)

print (''.join(newick))

