import lineTools import json import os # for getting script path, etc. def relativePath(path): # the only argument, path, is relative to the directory this script is stored in return os.path.join(os.path.dirname(__file__), path) # print relativePath("lines.json") with open(relativePath("lines.json"), "r+") as aFile: with open(relativePath("statistics.txt"), "w+") as bFile: content = aFile.read() lines = json.loads(content) for line in lines: bFile.write("Line " + str(lines.index(line) + 1) + " - " + str(lineTools.lineLength(line)) + "; center: " + str(lineTools.pointCentre(line)[0]) + ", " + str(lineTools.pointCentre(line)[1]) + "; number of nodes: " + str(len(line)) + "\n")