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) lines = [lineTools.randomLine(i + 10) for i in range(10)] with open(relativePath("lines_bhw.json"), "w+") as aFile: # aFile.write(str(lines)) # alternative for easy data structures aFile.write(json.dumps(lines))