def writeFile(self): """Write the end result to the file""" fileN = open ("game.data","w") write_recursion.write(fileN, self.root) fileN.close() # this doesn't work for some reason with open("game.data", "r+w") as f: for line in f: if line.strip(): f.write(line)
def writeFile(self): """Write the end result to the file""" fileN = open("game.data", "w") write_recursion.write(fileN, self.root) fileN.close() # this doesn't work for some reason with open("game.data", "r+w") as f: for line in f: if line.strip(): f.write(line)
from Tree import TreeNode import write_recursion sampleTree = TreeNode() sampleTree.setValue(7) sampleTree.addLeft(6) sampleTree.addRight(10) y = sampleTree.getLeft() x = sampleTree.getRight() x.addLeft(9) x.addRight(57) y.addLeft(8) y.addRight(47) def print_tree(tree): if tree == None: return print tree.item print_tree(tree.left) print_tree(tree.right) print_tree(sampleTree) gameData = open("testData.txt", "w") write_recursion.write(gameData, sampleTree)
import write_recursion sampleTree = TreeNode() sampleTree.setValue(7) sampleTree.addLeft(6) sampleTree.addRight(10) y = sampleTree.getLeft() x = sampleTree.getRight() x.addLeft(9) x.addRight(57) y.addLeft(8) y.addRight(47) def print_tree(tree): if tree == None: return print tree.item print_tree(tree.left) print_tree(tree.right) print_tree(sampleTree) gameData = open("testData.txt", "w") write_recursion.write(gameData, sampleTree)